ProgrammingModerateGATE CS · Campus placements

What is the popcount of (1ULL << 40) | (1ULL << 3)?

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

Correct answer: A. 2

Two bits are set, at positions 3 and 40, so the popcount is 2. Using a plain int for the shift would be undefined at position 40.

More C Programming questions

Exams that ask this topic