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.

advertisement

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?

advertisement
  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.

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!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.