typeover
curriculum

Curriculum Types Pointers exercise 2 · mcq

Pointers

When a function only READS through a pointer (never writes), Zig's idiom is to mark the pointer const. Pick the right signature for a function that takes a pointer just to read the value it points at.

TypeScript reference
Pick the idiomatic Go translation

About this theme

TypeScript has no pointer syntax — everything is a reference under the hood. Zig has dedicated syntax for pointers, and several flavours: *T (single pointer to one T), *const T (read-only single pointer), and — surfaced later in the curriculum — [*]T (many-item pointer, length unknown) and ?*T (nullable single pointer). This theme focuses on the two-flavour core (*T + *const T) since those are the shapes you write every day; many-item and nullable pointers come up in Module 3 (memory) and Module 4 (errors) respectively when their natural use cases arrive. &value takes the address; p.* dereferences. The discipline: pick the narrowest flavour that fits the use case.