ProgrammingHardGATE CS · Campus placements

uint32_t n = 0xB6u; the loop while (n) { n &= n - 1; count++; } runs with count starting at 0. What is count when the loop ends?

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

Correct answer: A. 5

n &= n - 1 clears the lowest set bit on each pass, so the loop runs once per set bit. 0xB6 = 1011 0110 has five 1 bits.

More C Programming questions

Exams that ask this topic