Go pointers

A pointer stores the memory address of a value rather than a separate copy of that value. Dereferencing a pointer accesses the value at that address, and a nil pointer points to no value.

Minimal example

go
func main() {
    count := 5
    ptr := &count
    *ptr = 8
    fmt.Println(count)
}

Learn this concept

Lesson 1.5 · Structs, pointers, slices and maps

Used in exercises

Exercise 1.8 · Practice: write your first Go program Exercise 1.11 · Token bucket limiter with lazy refill
Prerequisite conceptsGo structs