ProgrammingHardGATE CS · Campus placements

A loop while (!(x & 1)) { x >>= 1; c++; } counts the trailing zero bits of a nonzero uint32_t x = 0b101000. What is c?

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

Correct answer: C. 3

The loop shifts out the low zero bits until bit 0 is set. In 101000 there are three trailing zeros, so c is 3. The loop never ends for x = 0, so the input must be nonzero.

More C Programming questions

Exams that ask this topic