xxxxxxxxxx
package main
import "fmt"
func main() {
var theArray [3]string
theArray[0] = "India" // Assign a value to the first element
theArray[1] = "Canada" // Assign a value to the second element
theArray[2] = "Japan" // Assign a value to the third element
fmt.Println(theArray[0]) // Access the first element value
fmt.Println(theArray[1]) // Access the second element valu
fmt.Println(theArray[2]) // Access the third element valu
}
xxxxxxxxxx
var a [10]int // declare an int array with length 10. Array length is part of the type!
a[3] = 42 // set elements
i := a[3] // read elements
// declare and initialize
var a = [2]int{1, 2}
a := [2]int{1, 2} //shorthand
a := [ ]int{1, 2} // elipsis -> Compiler figures out array length
xxxxxxxxxx
package main
import "fmt"
func main() {
var theArray [3]string
theArray[0] = "India" // Assign a value to the first element
theArray[1] = "Canada" // Assign a value to the second element
theArray[2] = "Japan" // Assign a value to the third element
fmt.Println(theArray[0]) // Access the first element value
fmt.Println(theArray[1]) // Access the second element valu
fmt.Println(theArray[2]) // Access the third element valu
}