Curriculum Basics Hello and output exercise 5 · fill-word
Hello and output
Fill the missing keyword. The writeStreamingAll call returns an
error union — leaving the return value uncaught is a compile
error. The keyword you need propagates the error up to the
enclosing function's !void return.
TypeScript reference
Fill the blanks →
About this theme
Two reflexes Zig wants you to internalise on day one.
- Imports use a builtin, not a keyword.
const std = @import("std");binds the standard library to a name. There's noimportkeyword and nousekeyword.@importis one of dozens of compiler builtins (everything starting with@) — you don't need the full list, just the muscle memory. maintakes aninit: std.process.Init. Zig's entry point used to be parameterless; modern Zig threads I/O capabilities (and soon, allocator handles) through anInitvalue the runtime constructs for you. You handinit.ioto anything that touches files / stdout / stderr. The signature ispub fn main(init: std.process.Init) !void— the!voidsays "may fail with an error".
Writing to stdout therefore reads as: get the stdout File handle, ask it to stream a slice of bytes through init.io.
try std.Io.File.stdout().writeStreamingAll(init.io, "hello\n");
try propagates the error if the write fails; !void in the main signature is what allows it. We'll come back to error unions properly in the errors module.