Complete the code to declare a nested struct field.
type Person struct {
Name string
Address [1]
}
type Address struct {
City string
Zip int
}The field Address inside Person must be of type Address to nest the struct.
Complete the code to create a variable of nested struct type.
var p [1] p = Person{ Name: "Alice", Address: Address{ City: "Wonderland", Zip: 12345, }, }
Address instead of Person.The variable p must be of type Person to hold the nested Address struct.
Fix the error in accessing the nested struct field.
fmt.Println(p.[1].City)City directly from p.To access the city, you must first access the Address field inside p.
Fill both blanks to define and initialize a nested struct inline.
p := Person{
Name: "Bob",
Address: [1]{
City: "[2]",
Zip: 54321,
},
}The nested struct type is Address, and the city name is a string like Cityville.
Fill all three blanks to create a nested struct and print a nested field.
type Company struct {
Name string
Founder [1]
}
type Founder struct {
FirstName string
LastName string
}
func main() {
c := Company{
Name: "TechCorp",
Founder: [2]{
FirstName: "Jane",
LastName: "Doe",
},
}
fmt.Println(c.Founder.[3])
}The Founder field in Company is of type Founder. We initialize it with Founder{...} and print the FirstName field.
