Golang & Concurrency (50 Qs)•Part 1: Go Language Core, Memory & Runtime Internals (1 - 15)
Method Receivers: Value Receiver (`(t T)`) vs. Pointer Receiver (`(t *T)`).
senior LevelgolangGo Language Core
In Simple Words:
- Pointer Receiver
(t *T):- Allows mutating the receiver struct.
- Avoids copying large structs on every method invocation.
- Satisfies interfaces when holding pointer values.
- Value Receiver
(t T):- Operates on a full shallow copy; mutations do not affect the caller.
- Safe for concurrent read access.
- Preferred for small primitive wrappers or immutable value types.