Monday, July 28, 2014

C Programming

1. 
The keyword used to transfer control from a function back to the calling function is
A.switchB.goto
C.go backD.return
2. 
What is the notation for following functions?
1.  int f(int a, float b)
    {
        /* Some code */
    }

2.  int f(a, b)
    int a; float b;
    {
        /* Some code */
    }
A.1. KR Notation
2. ANSI Notation
B.1. Pre ANSI C Notation
2. KR Notation
C.1. ANSI Notation
2. KR Notation
D.1. ANSI Notation
2. Pre ANSI Notation
3. 
How many times the program will print "IndiaBIX" ?
#include<stdio.h>

int main()
{
    printf("IndiaBIX");
    main();
    return 0;
}
A.Infinite timesB.32767 times
C.65535 timesD.Till stack overflows
4. 
What will be the output of the program in 16 bit platform (Turbo C under DOS)?
#include<stdio.h>

int main()
{
    int fun();
    int i;
    i = fun();
    printf("%d\n", i);
    return 0;
}
int fun()
{
    _AX = 1990;
}
A.Garbage valueB.0 (Zero)
C.1990D.No output
5. 
What will be the output of the program?
#include<stdio.h>
void fun(int*, int*);
int main()
{
    int i=5, j=2;
    fun(&i, &j);
    printf("%d, %d", i, j);
    return 0;
}
void fun(int *i, int *j)
{
    *i = *i**i;
    *j = *j**j;
}
A.5, 2B.10, 4
C.2, 5D.25, 4
6.
What will be the output of the program?
#include<stdio.h>
int i;
int fun();

int main()
{
    while(i)
    {
        fun();
        main();
    }
    printf("Hello\n");
    return 0;
}
int fun()
{
    printf("Hi");
}
A.HelloB.Hi Hello
C.No outputD.Infinite loop
7. 
What will be the output of the program?
#include<stdio.h>
int reverse(int);

int main()
{
    int no=5;
    reverse(no);
    return 0;
}
int reverse(int no)
{
    if(no == 0)
        return 0;
    else
        printf("%d,", no);
    reverse (no--);
}
A.Print 5, 4, 3, 2, 1B.Print 1, 2, 3, 4, 5
C.Print 5, 4, 3, 2, 1, 0D.Infinite loop
.
8. 
What will be the output of the program?
#include<stdio.h>
void fun(int);
typedef int (*pf) (int, int);
int proc(pf, int, int);

int main()
{
    int a=3;
    fun(a);
    return 0;
}
void fun(int n)
{
    if(n > 0)
    {
        fun(--n);
        printf("%d,", n);
        fun(--n);
    }
}
A.0, 2, 1, 0,B.1, 1, 2, 0,
C.0, 1, 0, 2,D.0, 1, 2, 0,
9. 
What will be the output of the program?
#include<stdio.h>
int sumdig(int);
int main()
{
    int a, b;
    a = sumdig(123);
    b = sumdig(123);
    printf("%d, %d\n", a, b);
    return 0;
}
int sumdig(int n)
{
    int s, d;
    if(n!=0)
    {
        d = n%10;
        n = n/10;
        s = d+sumdig(n);
    }
    else
        return 0;
    return s;
}
A.4, 4B.3, 3
C.6, 6D.12, 12
 10.
What will be the output of the program?
#include<stdio.h>

int main()
{
    void fun(char*);
    char a[100];
    a[0] = 'A'; a[1] = 'B';
    a[2] = 'C'; a[3] = 'D';
    fun(&a[0]);
    return 0;
}
void fun(char *a)
{
    a++;
    printf("%c", *a);
    a++;
    printf("%c", *a);
}
A.ABB.BC
C.CDD.No output

No comments: