← Back to archive

Stdle #146 · structs · 2026-10-30

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 Point = struct { x: i32, y: i32 };
const points = [_]Point{
.{ .x = 1, .y = 2 },
.{ .x = 3, .y = 4 },
.{ .x = 5, .y = 6 },
};
var sum: i32 = 0;
for (points) |p| {
sum += p.x + p.y;
}
std.debug.print("{d}\n", .{sum});
}
Structs
4 attempts left

Answer & explanation