Machine-translated by Google. Questions are authored in English.
Top

Discussion

Bitwise | can be used to set multiple bits in number.

  • A.Yes
  • B.No

Answer: A

Correct answer: Yes

OR with a mask forces every position named by the mask to 1 and leaves the others as they were, and a mask may name any number of positions at once.

So item |= MOBILE | LAPPY sets both flags in a single operation. This is why OR is the natural operator for accumulating flags: each |= adds to the set without disturbing what is already there, and the operation is idempotent, so setting a bit that is already on changes nothing.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.