0PricingLogin
Go Academy · Lesson

What Are Pointers?

Address-of operator, dereferencing, nil pointers

Memory Addresses

Every variable lives at a memory address. A pointer stores that address. In Go, pointers are typed: a *int holds the address of an int.

Address-of Operator &

Use & to get the address of a variable:

package main
import "fmt"

func main() {
    x := 42
    p := &x
    fmt.Println(p)  // 0xc000... (address)
    fmt.Println(*p) // 42 (value at address)
}

All lessons in this course

  1. What Are Pointers?
  2. Pointers and Functions
  3. Pointer Receivers on Methods
  4. new() and When to Use Pointers
← Back to Go Academy