← Back to archive

Stdle #53 · unions · 2026-07-29

What does this Zig snippet output?

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

const std = @import("std");
const Shape = union(enum) {
circle: f64,
square: f64,
};
pub fn main() void {
const s = Shape{ .circle = 3.0 };
switch (s) {
.circle => |r| std.debug.print("r={d:.0}\n", .{r}),
.square => |side| std.debug.print("s={d:.0}\n", .{side}),
}
}
Unions
4 attempts left

Answer & explanation