~/Go Slices
Sep 19, 2024
In Go, slices are, as the name implies, slices of arrays.
A slice is composed of a pointer to an underlying array,
a length, and a capacity. The syntax to take a slice is
arr[start:end]
, where start
is inclusive, and end
is exclusive.
Omitting start
defaults to 0
, and omitting end
uses the slice/array’s length.
graph TD; A[Backing Array] -->|Reference| B[Slice]; B --> D[Length]; A --> E[Capacity]; B --> E