Arrays
Context
Section titled “Context”An array is a fixed‑size sequence of elements of a single type. The size is part of the type (e.g., [5]int). Arrays are value types – assigning copies the entire array.
Example
Section titled “Example”Declare, initialize, and iterate over arrays.
Code example
Section titled “Code example”package main
import "fmt"
func main() { var a [3]int // zero-valued array [0,0,0] b := [4]int{1, 2, 3, 4} // literal c := [...]int{10, 20, 30} // size inferred
a[0] = 42 fmt.Println(a, b, c)
// Iterate for i, v := range c { fmt.Printf("c[%d] = %d\n", i, v) }}Output
Section titled “Output”[42 0 0] [1 2 3 4] [10 20 30]c[0] = 10c[1] = 20c[2] = 30