Curriculum Basics Hello and output exercise 1 · mcq
Hello and output
TypeScript pulls in a module with the import keyword. Zig has no
import keyword — imports go through a compiler builtin instead.
Pick the idiomatic Zig translation.
TypeScript reference
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.