Go每日一题(5)
结构属性取值
package main import ( "fmt" "reflect" ) type person struct { name string age int } func main() { p := person{name: "Tom", age: 12} fmt.Println(reflect.TypeOf(p)) fmt.Println(p.name) fmt.Println((&p).name) // fmt.Println(p->name) // 失败:无效操作符 // fmt.Println((*p).name) // 失败:错误指针变量 }