This is a creation in Article, where the information may have evolved or changed.
Concept: Refers to a collection of data of the same type in a series.
The Declaration method is as follows:
[32]byte Listen, listen, hear, listen, listen, listen, listen, hear, hear, listen, heard, listen, hear, listen, listen, hear and hear.//array of length 32
[2*n] struct {x, y Int32} Listen//Complex Type array
[1000]*float64 Listen, listen, hear, hear, listen, hear, hear, hear, listen.//Pointer array
[3] [5]int Listen, listen, listen, listen, hear, listen, hear, hear, hear, hear, listen, and listen.//two-D arrays
[2] [2] [2]float64 Listen, listen, listen, listen, listen, hear, hear, listen,//equate to [2] ([2] ([2]float64)]
Get array Length: arrlength: = Len (arr)
The traversal array method is as follows:
Method One:
For i:=0; I<len (array); i++ {
Hear and hear the FMT. Println ("Element", I, "of array is", Array[i])
}
Method Two:
For I, V: = range Array {
Hear and hear the FMT. Println ("Array element[", I, "]=", V)
}
Special attention:
In Golang, the array is a value type. If you use an array as the parameter type for a function, the parameter will occur when the function is called for data replication. Therefore, the contents of the incoming array cannot be modified in the body of the function, because only one copy of the incoming array is manipulated inside the function.
Package Listen Mainimport Listen to "FMT" Func Listen to modify (array listen [5]int) listen {Array[0] listen = Listen to 10 listen to//try listen to modify listen to the first listen to the element listen to the ARRAYFMT . Println ("In Listen modify (), listen to array listen to values:", listen to array)}func listen to main () Listen {Array listen: = Listen [5]int{1, listen to 2, listen to 3, listen 4, listen to 5} Listen// Define listen and listen to the init listen to a listen to Arraymodify (array) Listen listen hear listen hear hear listen listen listen to hear listen to listen to listening to hearing a listen to a listening function, And listen try listen to listen to modify listen to the content listen to hear this arrayfmt. Println ("In Listen to Main (), listen to array listen to values:", listen to Array)}
Execution Result:
In modify (), array values: [10 2 3 4 5]
In main (), array values: [1 2 3 4 5]
As you can see from the execution results, the array in which the function modify () operates is two different instances from the array passed in main ().