1. What is the output of this C code?
-
#include <stdio.h>
-
void main()
-
{
-
int a = 5, b = -7, c = 0, d;
-
d = ++a && ++b || ++c;
-
printf("n%d%d%d%d", a, b, c, d);
-
}
a) 6 -6 0 0
b) 6 -5 0 1
c) -6 -6 0 1
d) 6 -6 0 1
Answer
Answer: d [Reason:] None.
2. What is the output of this C code?
-
#include <stdio.h>
-
void main()
-
{
-
int a = -5;
-
int k = (a++, ++a);
-
printf("%dn", k);
-
}
a) -3
b) -5
c) 4
d) Undefined
Answer
Answer: a [Reason:] None.
3. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
int x = 2;
-
x = x << 1;
-
printf("%dn", x);
-
}
a) 4
b) 1
c) Depends on the compiler
d) Depends on the endianness of the machine
Answer
Answer: a [Reason:] None.
4. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
int x = -2;
-
x = x >> 1;
-
printf("%dn", x);
-
}
a) 1
b) -1
c) 2 31 – 1 considering int to be 4 bytes
d) Either -1 or 1
Answer
Answer: b [Reason:] None.
5. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
if (~0 == 1)
-
printf("yesn");
-
else
-
printf("non");
-
}
a) yes
b) no
c) compile time error
d) undefined
Answer
Answer: b [Reason:] None.
6. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
int x = -2;
-
if (!0 == 1)
-
printf("yesn");
-
else
-
printf("non");
-
}
a) yes
b) no
c) run time error
d) undefined
Answer
Answer: a [Reason:] None.
7. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
int y = 0;
-
if (1 |(y = 1))
-
printf("y is %dn", y);
-
else
-
printf("%dn", y);
-
-
}
a) y is 1
b) 1
c) run time error
d) undefined
Answer
Answer: a [Reason:] None.
8. What is the output of this C code?
-
#include <stdio.h>
-
int main()
-
{
-
int y = 1;
-
if (y & (y = 2))
-
printf("true %dn", y);
-
else
-
printf("false %dn", y);
-
-
}
a) true 2
b) false 2
c) either option a or option b
d) true 1
Answer
Answer: c [Reason:] None.