← Back to archive

Stdle #106 · unions · 2026-09-20

What does this Zig snippet output?

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

const std = @import("std");
pub fn main() void {
const U = union(enum) {
int: i32,
float: f64,
none,
};
const val = U{ .int = 42 };
switch (val) {
.int => |n| std.debug.print("int: {d}\n", .{n}),
.float => |f| std.debug.print("float: {d}\n", .{f}),
.none => std.debug.print("none\n", .{}),
}
}
Unions
4 attempts left

Answer & explanation