Complete the code to declare a struct named Person.
type Person [1] {
Name string
Age int
}In Go, structs are declared using the keyword struct.
Complete the code to create a new Person instance with Name "Alice" and Age 30.
p := [1] Person{Name: "Alice", Age: 30}
Using & before a struct literal returns a pointer to the new struct.
Fix the error in the method receiver syntax to correctly define a method for Person.
func (p [1] Person) Greet() string { return "Hello, " + p.Name }
Methods with pointer receivers use * before the type name.
Fill both blanks to create a map from string to Person struct and add an entry.
people := make(map[1]Person) people["bob"] = [2]{Name: "Bob", Age: 25}
The map key type is [string] and the value is a struct literal struct.
Fill all three blanks to define an anonymous struct, assign values, and print the Name field.
user := [1] { Name: "Eve", Age: 28, } fmt.Println(user.[2]) var info [3] = user
An anonymous struct is declared with struct { ... }. Access the Name field and assign the same struct type to info.