通过指针操作

    1. type person struct{
    2. Name string
    3. Age int
    4. }
    5. func main() {
    6. Name: "joe",
    7. Age: 19,
    8. }
    9. a.Age = 13
    10. fmt.Println(*a)
    11. }

    匿名结构嵌套

    1. Name string
    2. Age int
    3. Contact struct {
    4. Phone, City string
    5. }
    6. }
    7. func main() {
    8. a := person{
    9. Age: 19,
    10. }
    11. a.Contact.Phone = "18826996633"
    12. fmt.Println(a)
    13. }

    拷贝赋值

    1. type person struct {
    2. string
    3. int
    4. }
    5. func main() {
    6. a := person{"joe",19}
    7. var b person
    8. b = a
    9. fmt.Println(b)