Arrays

suggest change

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

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

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

Learn more about arrays.

Array basics

main.go

	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))

Output:

Size of a1: 2.
Size of a2: 3

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents