Essential Go Basic types  Edit on GitHub      File Issue

Arrays

Arrays in Go have a fixed sized. They can’t grow.

They are used rarely. Instead in most cases we use slices.

A slice is growable and implemented as a view into its underlying array.

Array basics:

var a1 = [2]byte{3, 8} // array of 2 bytes
// when using [...] size will be deduced from { ... }
a2 := [...]int{1, 2, 3} // array of 3 integers

fmt.Printf("Size of a1: %d.\nSize of a2: %d\n", len(a1), len(a2))
Size of a1: 2.
Size of a2: 3

Zero value of array is array where all values have zero value.

Learn more about arrays.

  ↑ ↓ to navigate     ↵ to select     Esc to close