typeover
curriculum

Curriculum Memory ArrayList exercise 2 · mcq

ArrayList

TypeScript's nums.push(10) extends the array. Zig's equivalent on std.ArrayList is .append(...) — but the allocator must be passed in (unmanaged convention). Pick the right call.

TypeScript reference
Pick the idiomatic Go translation

About this theme

ArrayList(T) is Zig's growable slice — your TypeScript Array equivalent. In Zig 0.16 it's an unmanaged container by API convention: you initialize with the .empty literal, pass the allocator on every mutating call (append, insert, etc.), and call .deinit(allocator) to release. items is a []T view into the live elements; the capacity is hidden. The benefit of unmanaged: no per-list allocator pointer overhead, and the list type is a plain struct you can store in a hash map's value.