← Back to archive

Stdle #88 · structs · 2026-09-02

What does this Zig snippet output?

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

const std = @import("std");
const Rect = struct {
w: i32,
h: i32,
fn area(self: Rect) i32 {
return self.w * self.h;
}
fn perimeter(self: Rect) i32 {
return 2 * (self.w + self.h);
}
};
pub fn main() void {
const r = Rect{ .w = 5, .h = 3 };
std.debug.print("{d} {d}\n", .{ r.area(), r.perimeter() });
}
Structs
4 attempts left

Answer & explanation