This is a creation in Article, where the information may have evolved or changed.
In the go language, an array of arrays is a set of ordered elements of a specific length.
The array type of go consists of two parts-type and length, both of which are indispensable. An array is a contiguous memory space that stores elements of the same type, so determining the type of an array inevitably requires determining the type of storage elements and how many elements are stored.
In the Go language, the array length cannot be changed after it is defined .
An array is a value type, and each pass produces a copy.
Example:
Package Mainimport ("FMT" "StrConv") func main () {var a [5]int //define array of 5 integer FMT. Println ("EMP:", a)//integer 0 value is 0a[4] = 100//modify array FMT. Println ("Set:", a) fmt. Println ("Get:", a[4])//Output single value FMT. Println ("Len:", Len (a))//Array length b: = [5]int{45, 32, 12, 42, 55}//define array value for array definition fmt. Println ("DCL:", b) for z, y: = range B {//traversal array FMT. Println ("ran:", Z, y)}var Twod [2][3]string //two-D array for I: = 0; I < 2; i++ {//loop for J: = 0; J < 3; J + + {Twod[i][j] = StrConv. Itoa (i) + "-" + StrConv. Itoa (j)//modify array}}fmt. Println ("2d:", Twod)}
Output:
EMP: [0 0 0 0 0]set: [0 0 0 0 100]GET:100LEN:5DCL: [55]ran:0 45ran:1 32ran:2 12ran:3 42ran:4 552d: [[0-0 0-1 0-2] [1-0 1-1 1-2]]
Arrays of several initialization methods:
var a [10]intvar a = [10]int{0,1,2,3,4,5,6,7,8,9}var a = [...] Int{0,1,2,3,4,5,6,7,8,9}var a = [2][2]int{[2]int{1,1}, [2]int{2,2}}var a = [2][2]int{{1,1}, {2,2}}