C Programming Questions and Answers – Bitwise Operators – 2

«
»

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

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.     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
View Answer

Answer: d
Explanation: None.
advertisement
advertisement

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

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

Answer: a
Explanation: None.
advertisement

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

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

Answer: a
Explanation: None.
advertisement

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

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

Answer: b
Explanation: None.

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

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

Answer: b
Explanation: None.

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

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

Answer: a
Explanation: None.

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

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

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  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 true 2 or false 2
d) true 1
View Answer

Answer: a
Explanation: None.

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.