Essential Go Basic types  Suggest an edit

Arrays

Arrays in Go have a fixed sized. As such they are used rarely.

In most cases we use slices which can grow and shrink their size.

Zero value of array is array with values set to their zero value.

Learn more about arrays.

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

  ↑ ↓ to navigate     ↵ to select     Esc to close