Arrays have size - a fixed size, and cannot be resized (length is part of its type).

How to declare:


To create an empty array:

var a [2]string

an array of 2 values of type string.

Can not mix types

func main() {
	var a [2]int // if need just empty array

	b := [2]string{"one"} // with some elements in the array
	b[1] = "two"

	a[0] = 0
	a[1] = 1
	fmt.Printf("The whole array: %v, %vn", a, b)
	fmt.Printf("The 1st in array: %v, %vn", a[0], b[0])
	fmt.Printf("The 2nd in array: %v, %vn", a[1], b[1])
	fmt.Printf("Array type: %T, %Tn", a, b)
	fmt.Printf("Array lengh:  %v, %vn", len(a), len(b))

go arrays output