Back to course

Pointers: The Basics

Full Course: Zig Programming From Zero to Hero

Pointers in Zig

Pointers store the memory address of a value. Zig pointers are safe but explicit.

  • *T: Single item pointer.
  • [*]T: Multi-item pointer (array-like).

zig var x: i32 = 42; const ptr = &x;

// Dereferencing to get the value std.debug.print("Value: {d}\n", .{ptr.*});

// Changing value through pointer ptr.* = 100;

Zig does not allow null pointers by default. If you need a nullable pointer, use ?*T.