初学 go 语言,对 & 和 * 的适用场景不太理解
尤其在结构体中 ,如 testb 怎么打印结果为&{test} 而不是地址
package main
import "fmt"
type Test struct {
name string
}
func main() {
testa := Test{"test"}
fmt.Println(testa)
//结果{test}
testb := &Test{"test"}
fmt.Println(testb)
//结果 &{test}
testc := &Test{"test"}
fmt.Println(*testc)
//结果 {test}
testd := &Test{"test"}
fmt.Println(&testd)
//结果 0xc000006030
var a int = 1
fmt.Println(a)
//结果 1
fmt.Println(&a)
//结果 0xc00000c0d8
}