package main
import "fmt"
// 定义一个结构
type person struct {
Name string
Age int
Content struct {
Phone string
City string
}
}
func main() {
// 可以不使用&,但推荐使用,方便引用传递
a := &person{}
a.Name = "说易事"
a.Age = 26
a.Content.City = "南宁"
a.Content.Phone = "10086"
fmt.Println(a)
b := &person{Name: "李四", Age: 24}
fmt.Println(b)
}输出:
&{说易事 26 {10086 南宁}}
&{李四 24 { }}