← Back to archive

Stdle #37 · enums · 2026-07-13

What does this Zig snippet output?

A past puzzle — fully playable. 4 attempts, hints on wrong guesses.

const std = @import("std");
const Op = union(enum) {
add: i32,
mul: i32,
nop,
};
pub fn main() void {
const op = Op{ .add = 5 };
switch (op) {
.add => |v| std.debug.print("add {d}\n", .{v}),
.mul => |v| std.debug.print("mul {d}\n", .{v}),
.nop => std.debug.print("nop\n", .{}),
}
}
Enums
4 attempts left

Answer & explanation