Skip to content
Related Articles

Related Articles

C | Operators | Question 26
  • Difficulty Level : Basic
  • Last Updated : 28 Aug, 2013

What does the following statement do?

x  = x | 1 << n;

(A) Sets x as 2n
(B) Sets (n+1)th bit of x
(C) Toggles (n+1)th bit of x
(D) Unsets (n+1)th bit of x

Answer: (B)

Explanation: Let n be 3, the value of expression 1 << n would be 8 (In binary 00001000).

If we do bitwise or of binary 00001000 with any number x would set its (n+1)th bit from left side.

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :