My Go code:
package main
import (
"fmt"
)
type Point struct {
x int
y int
}
func main() {
fmt.Println(&Point{1, 2})
fmt.Printf("%v\n", &Point{1, 2})
fmt.Printf("%p\n", &Point{1, 2})
}
Output:
&{1 2}
&{1 2}
0xc00002c070
This does not match the documentation in https://godoc.org/fmt. The documentation says,
The default format for %v is:
bool: %t int, int8 etc.: %d uint, uint8 etc.: %d, %#x if printed with %#v float32, complex64, etc: %g string: %s chan: %p pointer: %p
As per the documentation above, for pointers, using %v should behave like using %p.
Why then does the output of fmt.Printf("%v\n", &Point{1, 2}) not match the output of fmt.Printf("%p\n", &Point{1, 2})?