Curriculum Types Structs
Structs
Zig structs are TypeScript object literals' closest cousin: const Point = struct { x: i32, y: i32 };. Instantiation uses dot-prefixed field initializers (Point{ .x = 3, .y = 4 }); access is .x (no surprise). Methods are declared INSIDE the struct as pub fn name(self: SelfType, ...) ReturnType — same shape as Go, but with the explicit self: parameter named like Python. No inheritance, no implicit this.
9 ready
01
pick one TypeScript declares a struct-like shape via type or
02
pick one TypeScript instantiates an object literal with { key: value }.
03
pick oneTypeScript attaches methods inside the type / class. Zig
04
fill blanksFill the missing keyword that declares a record type. Six
05
fill blanksFill the missing conventional name of the receiver parameter in
06
type one line Type the missing Zig line — instantiate a Point with x=3 and
07
type one line Type the missing Zig line — the method signature for area,
08
write a programWrite a complete Zig program that:
09
write a programWrite a complete Zig program with a method on a struct: