This is a creation in
Article, where the information may have evolved or changed.
An array is a value type in go, and if you assign an array to another array, it is actually a copy of the entire array
Array definitions: var <arrName> [N]<type>, n>=0. n If the size is different, the array type is not the same
You can use = = and! = to compare between arrays of the same type, but you cannot use < and >
Arrays of the same type can be assigned directly: var a = [10]int{1,2,3, 5:9} var b [10]int b =a
Array pointers and array of pointers
When you create an array with new, an array pointer is returned
var arrname [10]int//Array definition
var arr = [5]int{9, 5, 6, 1, 4}//Initialization
var arr = [5]int{9, 5, 4:9}//initialization, 4:9 index
Arr: = [5]int{9, 5, 6, 1, 4}//Initialization
Bubble sort
Func Main () {
var arr = [5]int{9, 5, 4:9}
For I: = 0; I < Len (arr); i++ {
For J: = i + 1; J < Len (arr); J + + {
If ARR[J] > Arr[i] {
ARR[J], arr[i] = Arr[i], arr[j]
}
}
}
Fmt. Println (arr)
}
Multidimensional arrays
var a = [2][2]int{[2]int{1,1}, [2]int{2,2}}
var a = [2][2]int{{1,1}, {2,2}}