Recall & Review
beginner
What is a method in Go?
A method in Go is a function with a special receiver argument. The receiver appears in its own argument list between the func keyword and the method name. Methods allow you to define behavior on types.
Click to reveal answer
intermediate
What is the difference between a value receiver and a pointer receiver in Go methods?
A value receiver gets a copy of the value, so changes inside the method do not affect the original. A pointer receiver gets the address, so changes inside the method can modify the original value.
Click to reveal answer
intermediate
How does Go decide which method to call when both pointer and value receivers exist?
Go automatically takes the address (&) of addressable values for pointer receiver methods and dereferences (*) pointers for value receiver methods, selecting the matching method based on the receiver expression type after conversion.
Click to reveal answer
intermediate
What happens if you call a method with a pointer receiver on a value variable?
Go automatically takes the address of the value variable to call the pointer receiver method, so the call works as if you passed a pointer.
Click to reveal answer
intermediate
Why might you choose a pointer receiver over a value receiver for a method?
You choose a pointer receiver to avoid copying large structs, to modify the original value, or to ensure consistency if some methods require pointers.
Click to reveal answer
In Go, which receiver type allows a method to modify the original struct?
✗ Incorrect
Pointer receivers get the address of the struct, so methods can modify the original value.
What happens if you call a value receiver method on a pointer variable in Go?
✗ Incorrect
Go automatically dereferences pointers when calling value receiver methods.
Which of these is true about method calls in Go?
✗ Incorrect
Go allows calling methods with pointer receivers on values by automatically taking the address.
Why might Go automatically take the address of a value when calling a method?
✗ Incorrect
Go helps by automatically taking the address so pointer receiver methods can be called on values.
Which receiver type copies the struct when calling a method?
✗ Incorrect
Value receivers get a copy of the struct, so the original is not changed.
Explain how Go handles method calls differently for pointer receivers versus value receivers.
Think about how Go treats the receiver when calling the method.
You got /4 concepts.
Describe when and why you would use a pointer receiver for a method in Go.
Consider performance and data modification needs.
You got /4 concepts.