โThis is the 12th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.โ
Write at the front 
Todayโs focus is on arrays
Array 
An Array is a fixed-length sequence of the same data type
- A length is part of an array and must be an integer that cannot be changed once it is defined (hence arrays are rarely used directly in Go).
- Each element of an array can be accessed by index subscripts ranging from 0 to the point where the array length is minus 1
len( )
Functions andcap( )
The array_length () function returns the length and capacity of an array
Define and initialize an array 
- Grammar
Define an array:varArray name [array length] Type//Type indicates the data Type, which can be any basic TypeGlobal initialization:var a [3]bool = [3]bool{true.false} // Uninitialized element values are the default values
var b = [5]int{1.2.3.4.5}
var c = [...]complex64{1+2i.2+1i.30.5 I.4+2i.50.1 I.6-5i} / / [...]. Indicates that the array length is determined by the initialization value
var d = [5]string{3: "Stubborn horns.".4: "LZH"} // Initialize elements with index numbers
var e = [6]float64{3.14.3.141.3.1415}
var f = [2]struct {
name string
age uint} {{Bighorn bull.18}, {"Little Horned Ox".8}} // The last line can be left out without a commaLocal initialization: g := [4]int{1.2}
h := [...]string{"Nami"."Sanji"."Zero"."Luffy"}
i := [9]bool{2: true.4:true}
j := [...]struct {
book string
price float64
}{
{"Go Programming Language".55.30 },
{"Go Web Programming".60.83}, // The last line must have a comma
}
Copy the code
- Sample
package main
import "fmt"
var a [3]bool = [3]bool{true.false} // Uninitialized element values are the default values
var b = [5]int{1.2.3.4.5}
var c = [...]complex64{1 + 2i.2 + 1i.3 - 0.5 I.4 + 2i.5 - 0.1 I.6 - 5i} / / [...]. Indicates that the array length is determined by the initialization value
var d = [5]string{3: "Stubborn horns.".4: "LZH"} // Initialize elements with index numbers
var e = [6]float64{3.14.3.141.3.1415}
var f = [2]struct {
name string
age uint} {{Bighorn bull.18}, {"Little Horned Ox".8}} // The last line can be left out without a comma
func main(a) {
g := [4]int{1.2}
h := [...]string{"Nami"."Sanji"."Zero"."Luffy"}
i := [9]bool{2: true.4: true}
j := [...]struct {
book string
price float64
}{
{"Go Programming Language".55.30},
{"Go Web Programming".60.83}, // The last line must have a comma
}
fmt.Println(a, b, c, d, e, f)
fmt.Println(g, h, i, j)
}
Copy the code
- Results
Second, go through the number group 
1. Conventional methods 
- Sample
package main
import "fmt"
func main(a) {
animal := [...]string{"The dog
"."The kitten
"."The pig
"."Little Rabbit
"."Bighorn ox
"}
for index := 0; index < len(animal); index++ {
fmt.Printf("animal[%d]=%s\n", index, animal[index])
}
fmt.Printf("There are %d animals.".len(animal))
}
Copy the code
- Results
2. For range: 
- Sample
package main
import "fmt"
func main(a) {
animal := [...]string{"The dog
"."The kitten
"."The pig
"."Little Rabbit
"."Bighorn ox
"}
for index, value := range animal {
fmt.Printf("animal[%d]=%s\n", index, value)
}
fmt.Printf("There are %d animals.".len(animal))
}
Copy the code
- Results
3. Arrays can be compared 
If both arrays are of the same length and type, you can compare the == and! Operators Can not compare two different types of arrays, otherwise the program will report an error
- Sample
package main
import "fmt"
var a = [3]int{1.2.3}
func main(a) {
b := [...]int{1.2.3}
c := [3]int{}
fmt.Println(a == b)
fmt.Println(a == c)
fmt.Println(b == c)
}
Copy the code
- Results
Write it at the back 
Thank you for watching
. If you have any questions, please point them out to