Go language Learning note eight: arrays
Array of earth people know. So just talk about the special (wonderful) wording of the go language.
I've been thinking about a person who has been involved in the design of two languages, but the grammar of the last two languages is quite different. This is self-denial, why not with the previous reunification.
Declaring an array
var variable_name [SIZE] variable_type
Example:
var x [10] int
Initializing an array
var x = [5] int {1, 2, 3, 4, 5}var y = [...] int {1, 2, 3, 4, 5}
The number of elements in the {} initialization array cannot be greater than the number in [].
If you ignore numbers in [] without setting the array size, the Go language sets the size of the array based on the number of elements.
Multidimensional arrays
var variable_name [SIZE1][SIZE2]...[SIZEN] variable_typevar x [5][10][4]int
Initializing a multidimensional array
a = [3][4]int{ {0, 1, 2, 3} , /* 第一行索引为 0 */ {4, 5, 6, 7} , /* 第二行索引为 1 */ {8, 9, 10, 11} /* 第三行索引为 2 */}
Passing an array to a function
void myFunction(param [10]int) {}或者void myFunction(param []int) {}
Other articles in this series address:
Https://github.com/zhangqunshi/golang_study
Go language Learning note eight: arrays