← Back to archive

Stdle #119 · structs · 2026-10-03

What does this Zig snippet output?

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

const std = @import("std");
const Vec2 = struct {
x: f32,
y: f32,
fn dot(self: Vec2, other: Vec2) f32 {
return self.x * other.x + self.y * other.y;
}
};
pub fn main() void {
const a = Vec2{ .x = 3.0, .y = 4.0 };
const b = Vec2{ .x = 1.0, .y = 2.0 };
std.debug.print("{d:.0}\n", .{a.dot(b)});
}
Structs
4 attempts left

Answer & explanation