Package Main;import ("FMT") func main () {//declares an array var a [3]int;a = [3]int{1, 2, 3};//declares and assigns var b [3]int = [3]int{1, 2, 3};//Sound Ming and Assignment (ellipsis type) var c = [3]int{1, 2, 3};//Declaration and assignment Shorthand D: = [3]int{1, 2, 3};//go the array length as part of the array type//e and F are two different types of variables, they cannot be assigned to the Operation Var e [2] Int;var F [3]int;//Specify the subscript initial 0 value, set the last element to 1var g [20]int = [20]int{19:1};//use ... Let go automatically calculate the array length h: = [...] Int{1, 2, 3, 4, 5};//go automatically calculates the required array length, the same variable gi: = [...] The elements of the int{19:1};//array are pointers, and the elements of the J array are a pointer to an int AA: = 1;bb: = 2;j: = [...] *INT{&AA, &bb};//Pointer to an array of k: = [5]int{1, 2, 3, 4, 5};//m is a pointer to an array of var m *[5]int = &k;//array comparison n: = [2]int{1, 2};o : = [2]int{1, 2};//returns a pointer to the array by new P: = new ([2]int);//can also be used [] to assign p[0], p[1] = 1, 2;//multidimensional array, two rows two columns Q: = [2][2]int{{1, 2}, {3, 4} };//automatically calculates multidimensional arrays, which must be top-level r: = [...] [2]int{{1, 2}, {3, 4}, {5, 6}};fmt. Printf ("%v\n%v\n%v\n%v\n%v\n%v\n%v\n%v\n%v\n%v\n%v\n", A, B, C, D, E, F, G, H, I, J, m);//Array compare FMT. PRINTLN (n = = O); fmt. PRINTLN (P); fmt. PRINTLN (q); fmt. Println (r);}
Arrays in the Go language