0Pricing
Zig Academy · Lesson

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

  1. Declaring Optional Types
  2. Unwrap Safely with if and orelse
  3. Optional Pointers and ?*T
  4. null Versus undefined
← Back to Zig Academy