C | Operators | Question 26

What does the following statement do?

filter_none

edit
close

play_arrow

link
brightness_4
code

x  = x | 1 << n;

chevron_right


(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



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.