Array assignment (copy)



examples/array-assignment/array_assignment.go
package main

import (
    "fmt"
)

func main() {
    var ar = [...]int{1, 2, 3}
    br := ar

    fmt.Println(ar)
    fmt.Println(br)
    ar[1] = 42
    fmt.Println(ar)
    fmt.Println(br)
}

examples/array-assignment/array_assignment.out
[1 2 3]
[1 2 3]
[1 42 3]
[1 2 3]

Assigning an array is by default creates a copy. Some cases this is what we want, in other cases we'd prefer to have reference / pointer to the same data in memmory.