go的 & 和 * 的区别,以及应用场景
& 在go中是直接取地址符
但是在第二项返回的是&{} 而不是0x…地址
这个就不太理解了
package main
import "fmt"
type Test struct {
name string
}
func main() {
test := Test{"test"}
fmt.Println(test)
//结果{test}
testa := &Test{"test"}
fmt.Println(testa)
//结果 &{test}
testc := &Test{"test"}
fmt.Println(*testc)
//结果 {test}
testd := &Test{"test"}
fmt.Println(&testd)
//结果 0xc000006030
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: