我刚开始学习go语言,想要打印出一个结构体变量的地址。以下是我的程序:
type Rect struct {
width int
name int
}
func main() {
r := Rect{4,6}
p := &r
p.width = 15
fmt.Println("-----",&p,r,p,&r)
}
这个的输出
_____0x40c130 {15 6} &{15 6} &{15 6}
但我想打印r变量的地址,因为我知道'&'代表地址,'*'指向指针位置的值,但是我无法打印r的地址,在这里我正在使用go-lang在线编辑器https://play.golang.org/ 同时,我希望将此地址存储在某个变量中。
fmt.Printf
和%p
动词吗?(链接:https://play.golang.org/p/DpXgfJwsW63) - mkopriva