Slices in Go
Explore slices in Go to understand how they wrap arrays, enabling flexible and efficient data management. Learn to create, resize, and append to slices while grasping key concepts like nil slices and slice length.
We'll cover the following...
Slices
Slices wrap arrays to give a more general, powerful, and convenient interface to sequences of data. Except for items with an explicit dimension such as transformation matrices, most array programming in Go is done with slices rather than simple arrays.
Slices hold references to an underlying array, and if you assign one slice to another, both refer to the same array. If a function takes a slice argument, changes it makes to the elements of the slice will be visible to the caller, analogous to passing a pointer to the underlying array.
A slice points to an array of values and also includes a length. Slices can be resized since they are just a wrapper on top of another data structure.
[]T is a slice with elements of type T ...