记录一个小问题,直接上代码。
type hello struct { world string } f := func(test *hello) { fmt.Printf("%p\n", test) // 0xc000012ba0 test = nil } test := &hello{world: "world"} f(test) fmt.Println(test) // &{world} fmt.Printf("%p\n", test) // 0xc000012ba0
这说明函数传递的永远是值,而指针的值就是指针的地址。
原创文章,作者:JLEJN,如若转载,请注明出处:https://www.beidanyezhu.com/a/29063.html