A pointer is a variable that stores the location of a value in memory. It lets you work with the original value directly instead of making a copy.
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}
By using pointers as function parameters, you pass the memory address of a variable rather than a copy of its value. This changes Go's default pass-by-value behavior here and allows the function to modify the original data directly.
Since arrays are pass-by-value types in Go (like booleans, numerics, and structs), passing them normally creates a full copy. Using pointers avoids that copying.