An array is a data type built into the go language, and for that type, it will be expanded by a few points
Array declaration and initialization
Arrays have the following kinds of ways of declaring initialization
// 方法1var arr [5]int// 方法2var arr = [5]int{1,2,3,4,5}// 方法3arr := [5]int{1,2,3,4,5}// 方法4arr := [...]int{1,2,3,4,5}// 特定赋值arr := [5]int{1:2,4:3}
Array using
var arr = [5]int{}arr[1]=3
var arr = [5]int{5,4,3,2,1}num := arr[1]
// for 遍历var arr = [5]int{1,2,3,4,5}for i :=0; i < len(arr); i++ { fmt.Println(arr[i])} // for range 遍历for _, item := range arr { fmt.Println(item)}
Arrays of the same length and type are of the same type, and they can be assigned directly between them, assigning values between variable lengths of array variables and requiring a single value
Array pointers
An array pointer is a collection of stored pointers
// 声明一个空指针的空数组var pr = [5]*int
So that each array element is a null pointer to a NULL pointer, you cannot give the value direct to a null pointer
Array pass-through parameter
In a previous article, the go language of the transfer of a topic, carried out, do not do a detailed expansion in this
When an array is passed a copy of the array, the modification of the arrays in the function does not result in the change of the array value in the final argument, and if the length of the array is particularly large, the value passed is very memory intensive, so the pointer to the array is passed, it is just a copy of the array pointer, Tangent points to the same array address