0PricingLogin
Zig Academy · Lesson

Overflow: + vs +% vs +|

Trapping, wrapping, and saturating math.

Numbers Have Limits

Every sized integer has a maximum it can hold. Push past it and you hit overflow, the moment a value tries to grow beyond its range.

Zig Catches Overflow

By default, the plain + operator traps overflow. In a safe build, going past the limit stops your program instead of corrupting the value.

var x: u8 = 255;
x = x + 1; // panics: overflow

All lessons in this course

  1. Arithmetic and Comparison Operators
  2. Overflow: + vs +% vs +|
  3. Bitwise Operators
  4. Boolean Logic and Short-Circuiting
← Back to Zig Academy