Application
Create new folder named src. In src folder, create new file named main.go as below:
package main
import "fmt"
func main() {
var a [5]int
a[0] = 5
a[1] = -6
a[2] = 11
a[3] = 20
a[4] = -2
fmt.Println("Length : ", len(a))
fmt.Println(a)
fmt.Println("List of Elements")
for i := 0; i < len(a); i++ {
fmt.Printf("%d the element of a is %d\n", i, a[i])
}
fmt.Println("\nList of Elements")
for index, value := range a {
fmt.Printf("%d the element of a is %d\n", index, value)
}
}
Output
Open Terminal windows in Visual Studio Code and run command line: go run main.go
Length : 5
[5 -6 11 20 -2]
List of Elements
0 the element of a is 5
1 the element of a is -6
2 the element of a is 11
3 the element of a is 20
4 the element of a is -2
List of Elements
0 the element of a is 5
1 the element of a is -6
2 the element of a is 11
3 the element of a is 20
4 the element of a is -2