Declaring Optional Types
Add ? to allow a missing value.
Sometimes There Is Nothing
Real programs hit cases where a value is simply absent: a lookup misses, a field is empty. Zig models this absence safely and on purpose.
The Optional Type
An optional type can hold either a real value of some type, or the special value null meaning nothing is there.
All lessons in this course
- Declaring Optional Types
- Unwrap Safely with if and orelse
- Optional Pointers and ?*T
- null Versus undefined