Curriculum Types Arrays vs slices
Arrays vs slices
Zig has two collection shapes where TypeScript has one. [N]T is a fixed-length array; the length N is part of the type, known at compile time. []T is a slice: a pointer plus a runtime length. Pass an array to a function and you pass a copy; pass a slice (built via arr[0..]) and you pass a view. Module 3 builds on this.
Exercises
9 ready
01
pick one
TypeScript writes const arr: number[] = [10, 20, 30];. Zig
02
pick one
When you don't want to repeat the length, use _ as the
03
pick one
To pass an array to a function that takes a slice, you build
04
fill blanks
Fill the missing single character that tells the compiler to
05
fill blanks
Fill the missing two-character operator that builds a slice
06
type one line
Type the missing Zig line — declare a fixed-length array nums
07
type one line
Type the missing Zig line — pass arr[0..] (the whole array
08
write a program
Write a complete Zig program that:
09
write a program
Write a complete Zig program that: