1. Find output of the following program
#include “stdio.h”
int main()
{
int x, y = 5, z = 5;
x = y == z;
printf(“%d”, x);
getchar();
return 0;
}
(a) Compiler Error
(b) 0
(c) 1
(d) 8
Answer
The result of a comparison operator is either 0 or 1 based on the comparison result. Since y is equal to z, value of the expression y == z becomes 1 and the value is assigned to x via the assignment operator.
2. Find output of the following program
#include
int main()
{
int a = (7, 8, 9);
printf(“%d”, a);
return 0;
}
(a) 7
(b) 9
(c) Garbage Value
(d) Compile time error
Answer
3. Find output of the following program
#include “stdio.h”
int main()
{
printf(“%d”, sizeof(printf(“SCABhopal”)));
return 0;
}
(a) SCABhopal4
(b) 4SCABhopal
(c) SCABhopal9
(d) 4
4Find output of the following program
#include “stdio.h”
int main()
{
int a = 80, b = 50, c = 60;
if (c > b > a)
printf(“TRUE”);
else
printf(“FALSE”);
return 0;
}
(a) TRUE
(b) FALSE
(c) Compiler error
(d) Blank Screen
5Find output of the following program
#include “stdio.h”
int main()
{
int x = 1;
int y = (x++, x++, x++);
printf(“%d %d\n”, x, y);
return 0;
}
(a) 4 3
(b) 4 4
(c) 1 1
(d) 3 3
Answer
6. Find output of the following program
#include “stdio.h”
int main()
{
int B = 0;
int A = (~B == 1);
printf(“%d”, A);
return 0;
}
(a) 0
(b) 1
(c) Compiler error
(d) Run time error.
Answer
7. Find output of the following program
#include “stdio.h”
int main()
{
int i = 6, j = 8, k = 12;
printf(“%d “, sizeof(k /= i + j));
printf(“%d”, k);
return 0;
}
(a) 4 12
(b) 4 2
(c) 2 1
(d) compile –time error
Answer
8. Find output of the following program
#include “stdio.h”
int main()
{
int a = 1;
int b = 1;
int c = a || –b;
int d = a– && –b;
printf(“a = %d, b = %d, c = %d, d = %d”, a, b, c, d);
return 0;
}
(a) a = 0, b = 1, c = 1, d = 0
(b) a = 0, b = 0, c = 1, d = 0
(c) a = 1, b = 1, c = 1, d = 1
(d) a = 0, b = 0, c = 0, d = 0
9. Find output of the following program
#include “stdio.h”
int main()
{
printf(“%d”, 1 << 2 + 3 << 4);
return 0;
}
(a) 512
(b) 52
(c) 112
(d) 0
10. Find output of the following program
# include “stdio.h”
int main()
{
int A = 10;
int B = 20;
A += B += 10;
printf (” %d %d”, A, B);
return 0;
}
(a) 40 20
(b) 40 30
(c) 30 30
(d) 30 40