/** * Go: passing a pointer allows function to change the * value of this thing being pointed at. This gives go a * backdoor return value. In some langs (eg C) this is very * useful, given multi-return in Go, not as much * * @author gtowell * Created August 2021 */ package main import "fmt" func main() { aa := 3 aap := &aa fmt.Printf("IN MAIN: %d %p %d\n", aa, aap, *aap) passer(aap) fmt.Printf("IN MAIN: %d %p %d\n", aa, aap, *aap) } func passer(poi *int) { fmt.Printf("IN PASSERa %p %d\n", poi, *poi) *poi = 5 qq := 7 fmt.Printf("IN PASSERb %p %d\n", poi, *poi) // changing the thing pointed to by poi // does NOT change the pointer outside the function. // pointer is passed by value poi = &qq qq = 9 fmt.Printf("IN PASSERc %p %d\n", poi, *poi) }