ProgrammingModerate

An unsigned short variable holds 65535 and is then incremented once with x++. What value does it hold?

  1. A. 65536
  2. B. 65535
  3. C. 1
  4. D. 0

Correct answer: D. 0

An unsigned short that overflows wraps modulo 65536, so 65535 + 1 becomes 0. Signed overflow would be undefined, but unsigned wrap is defined.

More C Programming questions

Exams that ask this topic