1. Comment on the output of the following C code.
#include <stdio.h>
int main()
{
int i, n, a = 4;
scanf("%d", &n);
for (i = 0; i < n; i++)
a = a * 2;
}
a) Logical Shift left
b) No output
c) Arithmetic Shift right
d) Bitwise exclusive OR
2. What will be the output of the following C code?
#include <stdio.h>
void main()
{
int x = 97;
int y = sizeof(x++);
printf("x is %d", x);
}
a) X is 97
b) X is 98
c) X is 99
d) Run time error
3. What will be the output of the following C code?
#include <stdio.h>
void main()
{
int x = 4, y, z;
y = --x;
z = x--;
printf("%d%d%d", x, y, z);
}
a) 323
b) 223
c) 322
d) 233
4. What will be the output of the following C code?
#include <stdio.h>
void main()
{
int x = 4;
int *p = &x;
int *k = p++;
int r = p - k;
printf("%d", r);
}
a) 4
b) 8
c) 1
d) Run time error
5. What will be the output of the following 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
6. What will be the output of the following C code?
#include <stdio.h>
void main()
{
int a = -5;
int k = (a++, ++a);
printf("%d\n", k);
}
a) -3
b) -5
c) 4
d) Undefined
7. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = 2;
x = x << 1;
printf("%d\n", x);
}
a) 4
b) 1
c) Depends on the compiler
d) Depends on the endianness of the machine
8. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = -2;
x = x >> 1;
printf("%d\n", x);
}
a) 1
b) -1
c) 231 – 1 considering int to be 4 bytes
d) Either -1 or 1
9. What will be the output of the following C code?
#include <stdio.h>
int main()
{
if (~0 == 1)
printf("yes\n");
else
printf("no\n");
}
a) Yes
b) No
c) compile time error
d) undefined
10. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int x = -2;
if (!0 == 1)
printf("yes\n");
else
printf("no\n");
}
a) yes
b) no
c) run time error
d) undefined