Complete the code to define a method with a pointer receiver.
func (p [1] Person) SetName(name string) {
p.Name = name
}The method receiver must be a pointer to modify the original struct. Using *Person allows changes to affect the original instance.
Complete the code to call the method with a pointer receiver correctly.
p := Person{Name: "Alice"}
p.[1]("Bob")Method names in Go are case-sensitive and usually start with a capital letter if exported. The method defined is SetName.
Fix the error in the method receiver declaration to allow modifying the struct.
func (p [1] Person) UpdateAge(age int) {
p.Age = age
}To modify the original struct, the receiver must be a pointer type *Person. Using a value receiver copies the struct and changes won't persist.
Fill both blanks to create a pointer receiver method that increments Age by 1.
func (p [1] Person) [2]() { p.Age++ }
The receiver must be a pointer *Person to modify the original struct. The method name IncrementAge follows Go naming conventions with capital letter.
Fill all three blanks to define a pointer receiver method that resets Name and Age.
func (p [1] Person) [2]() { p.Name = [3] p.Age = 0 }
The receiver must be a pointer *Person to modify the original struct. The method name Reset is capitalized. The empty string "" resets the Name field.