October 2015
Beginner to intermediate
400 pages
14h 44m
English
An array is a fixed-length sequence of zero or more elements of a particular type. Because of their fixed length, arrays are rarely used directly in Go. Slices, which can grow and shrink, are much more versatile, but to understand slices we must understand arrays first.
Individual array elements are accessed with the conventional subscript
notation, where subscripts run from zero to one less than the array length.
The built-in function len returns the number of elements in the
array.
var a [3]int // array of 3 integers fmt.Println(a[0]) // print the first element fmt.Println(a[len(a)-1]) // print the last element, a[2] // Print the indices and elements. for i, v := range a { fmt.Printf("%d %d\n", ...