Quiz Entry - updated: 2026.07.07
What happens when you shift by more than the bit width?
Undefined behavior in C — shifting by an amount ≥ the type's width (or by a negative amount) has no guaranteed result.
For a 32-bit integer:
// Undefined!
x << 32
// Undefined!
x >> 32
// Undefined!
x << -1
What happens in practice: Often the shift amount is taken mod 32 (or mod 64), so x << 32 might equal x << 0 = x, but you cannot rely on this.
Safe practice: Always ensure 0 <= shift_amount < bit_width.