Values & References8 / 18
Up next

Optionals vs pointers

const std = @import("std");

pub fn main() void {
    // an optional holds a value or null, checked with if-capture
    var maybe: ?i32 = null;
    maybe = 42;
    // orelse supplies a default when it is null
    const got = maybe orelse -1;
    std.debug.print("{d}\n", .{got});
}
What you're solving

?T guards against a missing value