ProgrammingHardGATE CS · Campus placements

int x = 12; x &= x - 1; What is x?

  1. A. 12
  2. B. 8
  3. C. 4
  4. D. 0

Correct answer: B. 8

x - 1 is 11 = 1011, and 12 = 1100, so their AND is 1000 = 8. This is the one-step clear of the lowest set bit.

More C Programming questions

Exams that ask this topic