- &
Array assignment (pointer)
examples/array-assignment-pointer/array_assignment_pointer.go
package main import ( "fmt" ) func main() { var ar = [3]int{1, 2, 3} br := &ar fmt.Println(ar) fmt.Println(br) ar[1] = 42 fmt.Println(ar) fmt.Println(br) fmt.Println(ar[1]) fmt.Println(br[1]) }
[1 2 3] &[1 2 3] [1 42 3] &[1 42 3] 42 42
This way br is a poiner to ar so they refer to the same data in memory. Even though br is a pointer we can still access elements in the same way as in the original array.
We'll discuss pointers in depth later on.