Built-in function append(slice, elements...) adds element to a slice and returns a new slice.

Append a single value

https://codeeval.dev/gist/3d66e56209e8b48e47c26905a3ca6ce3

Append multiple values

https://codeeval.dev/gist/6e1c390b76f52e6e83d0dd8c3daa27ad

Append a slice to a slice

https://codeeval.dev/gist/7367e2d0f59764b68a2bee4a39833272

Append might create a new slice

Maybe you noticed the pattern a = append(a, ....).

A slice uses an array of fixed size for storage. When number of slice elements exceeds size of array, append needs to re-allocate the array and create a new slice. For efficiency the newly allocated array has some spare elements, so that we don't have to re-allocate backing array every time we append an element to a slice.

This program shows how many elements it takes to re-allocate new array.

https://codeeval.dev/gist/37cc703e6f3a2b1a183d18276b7a97f8

As you can see, the number of appends needed to re-create the array increases with the size of the slice.

Go doesn't allow comparing slices so we use the fact that in current implementation we can take address of the slice (%p) and that address can be used as identity of slice.

This is an internal implementation detail that might change in the future.