In Zig, values can be assigned to constants or variables. |
|
![]() const std = @import("std"); |
|
pub fn main() anyerror!void { |
|
Here, we assign the value |
const c: bool = true; |
Here, we assign the value |
var v: bool = false; v = true; |
Note that the compiler can often infer types for you. |
const inferred_c = true; var inferred_v = true; |
To create an uninitialized constant or variable, assign |
const undefined_c: bool = undefined; var undefined_v: bool = undefined; |
Assignments can also be used to ignore expressions. |
_ = c; _ = v; _ = inferred_c; _ = inferred_v; _ = undefined_c; _ = undefined_v; } |
Next example: Integers.