As you would find in other languages, Go arrays are containers for storing sequenced values of the same type that are numerically indexed. The following code snippet shows samples of variables that are assigned array types:
var val [100]int var days [7]string var truth [256]bool var histogram [5]map[string]int
golang.fyi/ch07/arrtypes.go
Notice the types that are assigned to each variable in the previous example are specified using the following type format:
[<length>]<element_type>
The type definition of an array is composed of its length, enclosed within brackets, followed by the type of its stored elements. For instance, the days
variable is assigned a type [7]string
. This is an important distinction as Go's type system considers two arrays, storing the same type of elements but with different lengths, to be of different types. The following code illustrates this situation:
var days [7]string var weekdays [5]string
Even though...