# Arrays, slices (and strings): The mechanics of 'append'

## Metadata
- Author: [[go.dev]]
- Full Title: Arrays, slices (and strings): The mechanics of 'append'
- Category: #articles
- Summary: A slice in Go is a data structure that represents a portion of an array and consists of a length and a pointer to the first element of that array. When you modify a slice, you can change its contents, but the length of the slice remains unchanged unless you explicitly return a new slice after resizing it. The built-in `append` function allows you to add elements to a slice efficiently, creating a new underlying array if necessary.
- URL: https://go.dev/blog/slices
## Highlights
- Arrays have their place—they are a good representation of a transformation matrix for instance—but their most common purpose in Go is to hold storage for a slice. ([View Highlight](https://read.readwise.io/read/01jthj7cq5v7r368sf1mky95ga))
- A slice is a data structure describing a contiguous section of an array stored separately from the slice variable itself. *A slice is not an array*. A slice *describes* a piece of an array. ([View Highlight](https://read.readwise.io/read/01jthj9kfk2qkxsf2db1997m18))
- What exactly is this slice variable? It’s not quite the full story, but for now think of a slice as a little data structure with two elements: a length and a pointer to an element of an array. You can think of it as being built like this behind the scenes:
type sliceHeader struct {
Length int
ZerothElement *byte
}
slice := sliceHeader{
Length: 50,
ZerothElement: &buffer[100],
} ([View Highlight](https://read.readwise.io/read/01jthjca21aznhq9y5ve67124b))