Multiple Choice Questions and Answers for Bitwise Operators in C Language

List of C interview questions on “Bitwise Operators” along with answers, explanations and/or solutions:

1. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int c = 2 ^ 3;
  5.         printf("%d\n", c);
  6.     }
a) 1
b) 8
c) 9
d) 0
Answer: a
2. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         unsigned int a = 10;
  5.         a = ~a;
  6.         printf("%d\n", a);
  7.     }
a) -9
b) -10
c) -11
d) 10
Answer:c
3. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         if (7 & 8)
  5.         printf("Honesty");
  6.             if ((~7 & 0x000f) == 8)
  7.                 printf("is the best policy\n");
  8.     }
a) Honesty is the best policy
b) Honesty
c) is the best policy
d) No output
Answer:c
4. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 2;
  5.         if (a >> 1)
  6.            printf("%d\n", a);
  7.     }
a) 0
b) 1
c) 2
d) No Output.
Answer:c
5. Comment on the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i, n, a = 4;
  5.         scanf("%d", &n);
  6.         for (i = 0; i < n; i++)
  7.             a = a * 2;
  8.     }
a) Logical Shift left
b) No output
c) Arithmetic Shift right
d) bitwise exclusive OR
Answer:b
6. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int x = 97;
  5.         int y = sizeof(x++);
  6.         printf("x is %d", x);
  7.     }
a) x is 97
b) x is 98
c) x is 99
d) Run time error
Answer:a
7. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int x = 4, y, z;
  5.         y = --x;
  6.         z = x--;
  7.         printf("%d%d%d", x, y, z);
  8.     }
a) 3 2 3
b) 2 2 3
c) 3 2 2
d) 2 3 3
Answer:d
8. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int x = 4;
  5.         int *p = &x;
  6.         int *k = p++;
  7.         int r = p - k;
  8.         printf("%d", r);
  9.     }
a) 4
b) 8
c) 1
d) Run time error
Answer:c
9. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int a = 5, b = -7, c = 0, d;
  5.         d = ++a && ++b || ++c;
  6.         printf("\n%d%d%d%d", a, b, c, d);
  7.     }
a) 6 -6 0 0
b) 6 -5 0 1
c) -6 -6 0 1
d) 6 -6 0 1
Answer:d 
10. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int a = -5;
  5.         int k = (a++, ++a);
  6.         printf("%d\n", k);
  7.     }
a) -3
b) -5
c) 4
d) Undefined
Answer:a 
11. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 2;
  5.         x = x << 1;
  6.         printf("%d\n", x);
  7.     }
a) 4
b) 1
c) Depends on the compiler
d) Depends on the endianness of the machine
Answer:a 
12. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = -2;
  5.         x = x >> 1;
  6.         printf("%d\n", x);
  7.     }
a) 1
b) -1
c) 2 ^ 31 – 1 considering int to be 4 bytes
d) Either b or c
Answer:b 
13. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         if (~0 == 1)
  5.             printf("yes\n");
  6.         else
  7.             printf("no\n");
  8.     }
a) yes
b) no
c) Compile time error
d) Undefined
Answer:b 
14. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = -2;
  5.         if (!0 == 1)
  6.             printf("yes\n");
  7.         else
  8.             printf("no\n");
  9.     }
a) yes
b) no
c) Run time error
d) Undefined
Answer:a 
15. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int y = 0;
  5.         if (1 |(y = 1))
  6.             printf("y is %d\n", y);
  7.         else
  8.             printf("%d\n", y);
  9.  
  10.     }
a) y is 1
b) 1
c) Run time error
d) Undefined
Answer:a 
16. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int y = 1;
  5.         if (y & (y = 2))
  6.             printf("true %d\n", y);
  7.         else
  8.             printf("false %d\n", y);
  9.  
  10.     }
a) true 2
b) false 2
c) Either option a or option b
d) true 1
Answer:c

Related

Multiple Choice Questions 3895793467535324482

Post a Comment

emo-but-icon

item