可以在声明嵌套结构体时初始化结构体数组。

例如:

type Person struct {

    Name string

    Age int

}

type School struct {

    Name string

    Students []Person

}

school := School{

    Name: "ABC School",

    Students: []Person{

        Person{Name: "Tom", Age: 10},

        Person{Name: "Mary", Age: 12},

    },

}

在上面的例子中,School 结构体包含一个名为 Students 的 Person 类型的数组。在声明 School 结构体时,可以通过对 Students 属性初始化来为其赋值。注意,初始化结构体数组时需要使用花括号 {} 包裹每个元素的属性赋值。