Unsigned wraparound reduces an out-of-range arithmetic result into the representable range by modular reduction. For size_t, arithmetic behaves as though it computes modulo SIZE_MAX + 1. section 4.1.2
A value crossing the boundary
For a size_t value, SIZE_MAX + 1 becomes 0, while 0 - 1 becomes SIZE_MAX. More generally, adding -1 to a value a produces a - 1 through wraparound. The same modular behavior explains clock calculations such as (8 + 6) % 12 == 2 and minute calculations using a % 60. section 4.1.2
Several rules make the behavior precise:
- Unsigned arithmetic wraps around when its result exceeds the type's range. section 4.1.2
- Unsigned division and remainder require a nonzero second operand. section 4.1.2
- Unsigned / and % cannot overflow because their results are no larger than their operands. section 4.1.2
- Loop code using unsigned indices should handle wraparound explicitly, such as checking the type maximum before incrementing. section 15.0


