Address of struct

fmt.Println(&person{name: “Ann”, age: 40})
why this returns "&{Ann,40} intead of an address in hexadecimal?

use Printf
fmt.Printf("%p\n", &person{name: “Ann”, age: 40})

fmt.Println does not return anything. But it has the sideeffect of writing something to stdout.

Println is documented to be equivalent to applying the format %v to each argument, separating them by spaces and ending with a newline.

%v prints in a default format, which is for structs (unless they implement fmt.Stringer) simply printing the fields values in curly braces. References get a & in front of them.

To actually see the address, do as @bigpigeon suggests.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.