Primitives
- unsigned integers:
u8, u16, u32, u64, usize, @
- signed integers:
i8, i16, i32, i64, isize, @
- single and double precision floats:
f32, f64
- arrays and slices:
[n]T, []T
Literals
// values.zig
const io = @import("std").io;
pub fn main(args: [][]const u8) -> %void {
// Declarations can be annotated with type
const id: u64 = 1337;
// Compiler can infer the type in some cases
const name = "Zig"; // []const u8
// Value of age and height are mutable, name and id are constant
var age: u8 = 27;
var height = 192.2; // f32
// Arguments can be passed to printf to format a string.
%%io.stdout.printf("Hello, {}! You are {}\n", name, age);
}
Operators
// operators.zig
const io = @import("std").io;
pub fn main(args: [][]const u8) -> %void {
// Integer addition and subtraction
%%io.stdout.printf("1 + 2 = {}", u32(1) + 2);
%%io.stdout.printf("1 - 2 = {}", i32(1) - 2);
// Boolean logic
%%io.stdout.printf("true AND false is {}", true and false);
%%io.stdout.printf("true OR false is {}", true or false);
%%io.stdout.printf("NOT true is {}", !true);
}