an array as an argument, we pass a copy of the array not a reference to the array. package main func main() { names := [4]string {"ada", "lovelace", "tom", "jerry"} f1(names) println(names[0]) } func f1(a [4]string) { a[0] = "marie" }
can modify it, then we pass the address of names to f1. package main func main() { names := [4]string {"ada", "lovelace", "tom", "jerry"} f1(&names) println(names[0]) } func f1(a *[4]string) { a[0] = "marie" }
a main.go:8: &a escapes to heap main.go:11: &a[i] escapes to heap main.go:8: main ... argument does not escape main.go:11: main ... argument does not escape with ft.Printf