Pointers hold memory addresses: *T points to T, &x takes address, *p dereferences. Go has pointers but no pointer arithmetic—safer than C, simpler than Rust lifetimes for most code.
When pointers matter
- Mutate function arguments
- Avoid copying large structs
- Share mutable state (carefully—prefer channels for concurrency)
- Represent optional or nullable values before generics
new vs composite literals
new(T) allocates zero value and returns *T. Often &T{...} is clearer for structs with initial fields.
Important interview questions and answers
- Q: Pointer arithmetic?
A: Not allowed in Go—unlike C/C++. - Q: nil pointer?
A: Zero value of pointers is nil; dereferencing nil panics—check before use.
Self-check
- What operator gets the address of x?
- What happens when you dereference a nil pointer?
Pitfall: Dereferencing nil panics—always guard or initialize pointers before *p access.
Interview prep
- Pointer arithmetic?
Not allowed—unlike C/C++.
- Nil pointer dereference?
Panics at runtime—check before dereferencing.