Quiz Entry - updated: 2026.07.14
What are the key differences between unsigned and signed integers in C?
Unsigned wraps predictably (mod 2^w) and right-shifts logically; signed has a negative range, sign-aware right shifts, and — in C — overflow is undefined behavior.
| Property | Unsigned | Signed (Two's Complement) |
|---|---|---|
| Range | 0 to 2^w - 1 | -2^{w-1} to 2^{w-1} - 1 |
| Overflow | Wraps (mod 2^w) | Undefined behavior! |
| Right shift | Logical (fill 0s) | Arithmetic (fill sign) |
| Comparison | Simple magnitude | Sign-aware |
| Division | Truncates to 0 | Truncates to 0 (but shift rounds to -∞) |
Critical warning: Signed overflow is undefined behavior in C - the compiler can assume it never happens and optimize accordingly!