A variable has a value. In Zig, a variable may also have an address.
| Section | Title |
|---|---|
| 1 | Addresses and Pointer Types |
| 2 | Single-Item Pointers |
| 3 | Many-Item Pointers |
| 4 | Slices |
| 5 | Pointer Arithmetic |
| 6 | Alignment |
| 7 | Lifetimes |
| 8 | Exercises |
Addresses and Pointer TypesA variable has a value. In Zig, a variable may also have an address.
Single-Item PointersA single-item pointer points to one value.
Many-Item PointersA many-item pointer points to the first item in a sequence.
SlicesA slice is a pointer and a length.
Pointer ArithmeticPointer arithmetic means forming a new pointer by moving from one element to another.
AlignmentMemory has addresses. Types also have alignment.
LifetimesA pointer is useful only while the value it points to still exists.
Exercises1. Write a function increment that takes i32 and adds 1 to the pointed-to value.