Pointers in Go
From the Go cheat sheet · Pointers · verified Jul 2026
Pointers
Pointer basics, dereferencing, and nil pointers
go
// Declare a pointer
var p *int
// Get address of variable
x := 42
p = &x
// Dereference (access value)
fmt.Println(*p) // 42
// Modify via pointer
*p = 100
fmt.Println(x) // 100
// Nil pointer check
if p != nil {
fmt.Println(*p)
}🎯 Use & to get address, * to dereference
📌 Go has no pointer arithmetic (safer than C)
💡 Struct fields accessed directly through pointer (no -> needed)
⚡ new() allocates zeroed memory and returns a pointer