ProgrammingHard

How many times does the loop x &= x - 1 run for x = 0b101100 before x becomes 0?

  1. A. 3
  2. B. 2
  3. C. 4
  4. D. 6

Correct answer: A. 3

Each pass clears the lowest set bit, so the loop runs once per set bit. 0b101100 has three set bits.

More C Programming questions

Exams that ask this topic