Go 结构体拷贝赋值与结构体指针赋值
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/f66ca3657d8df9fff3c2850fdf9358d8.png#pic_center)
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Hobby []string `json:"hobby "`
}
func structTest() {
p1 := Person{
Name: "柯南",
Age: 2,
Hobby: []string{"海盗", "睡觉", "打架"},
}
p2 := p1
fmt.Println(p1)
fmt.Println(p2)
fmt.Println("----------------------------")
p1.Name = "路飞"
fmt.Println(p1)
fmt.Println(p2)
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/de42146143cd6abe1edcabf6ffe05411.png#pic_center)
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Hobby []string `json:"hobby "`
}
func structPoint() {
p1 := &Person{
Name: "柯南",
Age: 2,
Hobby: []string{"海盗", "睡觉", "打架"},
}
p2 := p1
fmt.Println(p1)
fmt.Println(p2)
fmt.Println("----------------------------")
p1.Name = "路飞"
fmt.Println(p1)
fmt.Println(p2)
}