Curriculum Basics Functions exercise 3 · mcq
Functions
TypeScript returns multiple values as a tuple [a, b]. Zig
technically has anonymous tuples too (struct { i32, i32 }),
but the idiomatic shape for multi-return is a NAMED struct —
the field names make the call site read better (r.quotient
vs r[0]). Pick the Zig translation.
TypeScript reference
About this theme
Zig functions look like TS with the type annotations shifted: fn name(param: Type) ReturnType { ... }. Visibility is opt-in via pub fn — top-level functions are private by default. Zig has no tuple-return; multi-return uses a struct (the Zig idiom) or out-params. Function-level errors come later in the errors module; here we focus on the value-returning shape.