- What is the output of the following program?
int main()
{
char r=132;
printf(“%d\n”, r);
}
a. -132
b. -124
c. 132
d. None
Answer: b
Explanation of C MCQ Set 1
- Select the most appropriate output for the following C code:
main()
{
printf(“%d %d %d %d”,-6%5,6%5,-6%-5,6%-5);
}
a. -1 1 -1 1
b. 1 -1 1 -1
c. 1 -1 -1 1
d. Error
Answer:a
Explanationof C MCQ Set 1
- Select the most appropriate output of the following C code:
main()
{
int x=-2,b;
printf(“%d %i”,b,b=x=9/x);
}
a. Garbage -4
b. Garbage -2
c. -4 -4
d. Error
Answer: c
Explanationof C MCQ Set 1 - Select the most appropriate output for the following C code:
int main()
{ int i = 90;
int j = (i++, –i, i++);
printf(“%d %d\n”, i, j);
}
a. 91 91
b. 90 90
c. 91 90
d. Compiler Dependent
Answer: c
Explanationof C MCQ Set 1
5.Select the most appropriate output for the following C code:
main()
{ int x=-7810,d,e;
d=!x;
e=~x;
printf(“%d %d”,d,e);
}
a. 0 7811
b. 0 7809
c. 1 7809
d. 1 0
Answer:b
Explanationof C MCQ Set 1
6.Select the most appropriate output for the following C code:
main()
{
int r = -5, s = 1;
s = r &= s && 100;
printf(“%d %d”,r,s);
}
a. -100 1
b. 1 0
c. 1 1
d. Error
Answer: c
Explanationof C MCQ Set 1
7.Select the most appropriate output for the following C code:
int main()
{ int a1 = 51;
int b1 = 0;
int c2 = a1 || –b1;
int d3 = a1– && –b1;
printf(“a1 = %d, b1 = %d, c2 = %d, d3 = %d”, a1, b1, c2, d3);
}
a. a1 = 50, b1 = -1, c2 = 1, d3 = 1
b. a1 = 50, b1 = -2, c2 = 1, d3 = 1
c. a1 = 51, b1 = -1, c2 = 1, d3 = 1
d. None
Answer: a
Explanationof C MCQ Set 1
- What is the output of this C code? void main()
{
int x = 10;
if (x = 0)
printf(“Its zero”);
else
printf(“Its not zero”);
}
A. Its not zero
B. Its zero
C. Run time error
D. None
Ans:A
Explanationof C MCQ Set 1
- What is the output of this C code? void main()
{
int k = 8;
int x = 0 == 1 && k++;
printf(“%d %d”, x, k);
}
A. 0 9
B. 0 8
C. 1 9
D. 1 8
Ans:B
Explanationof C MCQ Set 1 - What is the output of this C code? void main()
{
char a = ‘a’;
int x = (a % 10)++;
printf(“%d”, x);
}
A. 6
B. Junk value
C. Compile time error
D. 7
Explanationof C MCQ Set 1