1. Consider the following C function
void swap (int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
}
In order to exchange the values of two variables x and y.
a) call swap (x, y)
b) call swap (&x, &y)
c) swap (x,y) cannot be used as it does not return any value
d) swap (x,y) cannot be used as the parameters are passed by value
Answer : D
2. Assuming, integer is 2 byte, What will be the output of the program?
#include<stdio.h>
int main()
{
printf(“%x\n”, -2<<2);
return 0;
}
A. ffff
B. 0
C. fff8
D. Error
Answer : C
3. What will be the output of the program?
#include<stdio.h>
int main()
{
int x=12, y=7, z;
z = x!=4 || y == 2;
printf(“z=%d\n”, z);
return 0;
}
A. z=0
B. z=1
C. z=4
D. z=2
Answer : B
4. What will be the output of the program?
#include<stdio.h>
int main()
{
int i=4, j=-1, k=0, w, x, y, z;
w = i || j || k;
x = i && j && k;
y = i || j &&k;
z = i && j || k;
printf(“%d, %d, %d, %d\n”, w, x, y, z);
return 0;
}
A. 1, 1, 1, 1
B. 1, 1, 0, 1
C. 1, 0, 0, 1
D. 1, 0, 1, 1
Answer : D
5. What will be the output of the program?
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, 1
B. Print 1, 2, 3, 4, 5
C. Print 5, 4, 3, 2, 1, 0
D. Infinite loop
Answer : C
6. 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. AB
B. BC
C. CD
D. No output
Answer : B
7. What will be the output of the program?
int main()
{
int fun(int);
int i = fun(10);
printf(“%d\n”, –i);
return 0;
}
int fun(int i)
{
return (i++);
}
A. 9
B. 10
C. 11
D. 8
Answer : A
C MCQ Set-15 Explanation
8. What will be the output of the program?
int check (int, int);
int main()
{
int c;
c = check(10, 20);
printf(“c=%d\n”, c);
return 0;
}
int check(int i, int j)
{
int *p, *q;
p=&i;
q=&j;
i>=45 ? return(p): return(q);
}
A. Print 10
B. Print 20
C. Print 1
D. Compile error
Answer : D
C MCQ Set-15 Explanation
9. What will be the output of the following C code?
#include<stdio.h>
void main()
{
char *s= “hello”;
char *p = s;
printf(“%s ,%s”, p+1, s+2);
}
a) Run time error
b) hello,llo
c) ello,llo
d) e,l
Answer : C
10. What will be the output of the following C code?
#include<stdio.h>
int main()
{
int ary[4] = {1, 2, 3, 4};
int *p = ary + 3;
printf(“%d\n”, p[-2]);
}
a) 1
b) 2
c) Compile time error
d) Some garbage value
Answer : B