A pointer is a variable that stores the memory address of a value. It allows direct access to the original value without copying it.
var p *int
Zero value: nil.
&p: Address of p.
*p: Value pointed to by p (dereferencing).
func main() { a := 10 fmt.Println(a) // 10 fmt.Printf("%T\n", a) // int // Declare a pointer and assign it the address of `a`: ptr := &a fmt.Println(ptr) // 0xed92788e008 fmt.Printf("%T\n", ptr) // *int fmt.Println(*ptr) // 10 // Change the value through the pointer: *ptr = 20 fmt.Println(a) // 20}
Using pointers as function parameters passes a memory address instead of a value copy. This overrides Go's default pass-by-value behavior and allows modification of the original data.