C Programming Questions and Answers – Bitwise Operators – 1

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Bitwise Operators – 1”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

1. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int c = 2 ^ 3;
  5.         printf("%d\n", c);
  6.     }

a) 1
b) 8
c) 9
d) 0
View Answer

Answer: a
Explanation: None.
advertisement
advertisement

2. What will be the output of the following C code?

  1.     #include <stdio.h>
  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
View Answer

Answer: c
Explanation: None.
advertisement

3. What will be the output of the following C code?

  1.     #include <stdio.h>
  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
View Answer

Answer: c
Explanation: None.
advertisement

4. What will be the output of the following C code?

  1.     #include <stdio.h>
  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
View Answer

Answer: c
Explanation: None.

5. Comment on the output of the following C code.

  1.     #include <stdio.h>
  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
View Answer

Answer: b
Explanation: None.

6. What will be the output of the following C code?

  1.     #include <stdio.h>
  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
View Answer

Answer: a
Explanation: None.

7. What will be the output of the following C code?

  1.     #include <stdio.h>
  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
View Answer

Answer: d
Explanation: None.

8. What will be the output of the following C code?

  1.     #include <stdio.h>
  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
View Answer

Answer: c
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.