Zig can infer a variable’s type when its value makes the type clear. When a value like 42 could have several types, an explicit annotation such as i32 removes the ambiguity. The compiler requires it to determine every variable and expression’s type. section 2.1.1
Use annotations with Zig’s type rules in mind:
- Annotate when context does not determine a value’s type; i32 is one suitable choice for 42. section 2.1.1
- Do not add annotations just for ceremony: Zig can infer many variable types. section 2.1.1
- An annotation does not make implicit conversions permissive; Zig requires explicit coercions. section 2.1.1
Table 2.1 Basic Zig types
| Name | Explanation |
|
Logical type. |
|
Signed (two’s-complement) integer type. In practice, you will mostly use |
|
Unsigned integer type. In practice, you will mostly use |
|
Special unsigned and signed integer types intended for usage as indices or offsets. These are equivalent to Rust’s |
|
Standard floating point types. |
|
You can think of this as a type that represents nothing, nada, zilch. More formally, there is only one possible value of |
|
Types in Zig are actually values, too! More specifically, type annotations in Zig are expressions like any other expression. With |
|
Special types, mainly for integer and float constants, that can’t exist at runtime. These are arbitrarily precise, so that they can coerce to any integer or float type that can hold them. For now, you can treat this as a curiosity. |
Compare Zig’s basic types, including signed and unsigned integers, floats, bool, and void. section 2.1.2





















