typeover
curriculum

Curriculum Basics Strings as slices exercise 5 · fill-word

Strings as slices

Fill the missing type. The element type of a Zig byte slice ([]const u8) is the byte: a single unsigned 8-bit integer. Two characters total.

TypeScript reference
Fill the blanks →

About this theme

There's no String type in Zig. String literals are byte slices typed as []const u8 — same shape as any other slice of read-only bytes. Length comes from .len (a usize), indexing returns a single u8 byte, and substring with s[a..b] produces another []const u8. The mental model from TypeScript needs one shift: a Zig string isn't a value-typed character sequence, it's a view into bytes.