ProgrammingHard

What is the value of 1u << 31 >> 31 in C?

  1. A. 0
  2. B. 1
  3. C. 2
  4. D. 2147483648

Correct answer: B. 1

1u << 31 sets the top bit, and shifting right 31 places brings it down to bit 0. The unsigned shift is well defined.

More C Programming questions

Exams that ask this topic