ProgrammingModerate
An unsigned short variable holds 65535 and is then incremented once with x++. What value does it hold?
- A. 65536
- B. 65535
- C. 1
- 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
- Which statement about left-shifting a negative signed integer in C is correct?
- How many subsets of {1, 2, 3, 4} (including the empty set) have XOR equal to 0?
- What is the result of (0xFFu >> 4) | (0x0Fu << 4) & 0xFF?
- How many times does cnt++ run in: for (i = 0; i < 10; i++) for (j = i; j < 10; j++) cnt++; ?
- How many iterations does for (i = 1; i < 1024; i = 2) do?
- A binary search over n = 10^6 sorted records, in the worst case, takes how many loop iterations?