Slices: A Pointer Plus a Length
Reference a window into an array.
Why Slices Exist
Arrays carry a fixed length, but functions often need to work with any length. A slice solves this by describing a flexible run of elements. 🔪
Two Pieces of Data
A slice is really just two things bundled together: a pointer to the first element and a length counting how many follow.
All lessons in this course
- Fixed-Size Arrays
- Slices: A Pointer Plus a Length
- Slicing with array[start..end]
- Iterating and Mutating Slices