ProgrammingHardTCS NQT · Infosys

uint32_t mask = 0; for (int i = 0; i <= 30; i += 3) mask |= 1u << i; How many set bits does mask have?

  1. A. 10
  2. B. 12
  3. C. 11
  4. D. 32

Correct answer: C. 11

The positions are 0, 3, 6, ..., 30, which are 11 values. Each one sets a distinct bit, so the popcount is 11.

More C Programming questions

Exams that ask this topic