By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
So far a variable has felt like a name for a value. Underneath, the computer keeps every value in a numbered box of memory, and each box has an address. When you write price := 1250, Go reserves a box, puts 1250 inside it, and remembers the name price so you can reach the box again.
A pointer is a value that holds one of those addresses. It does not hold the number 1250; it holds the location where 1250 lives. With a pointer you can read the value behind the address, or replace it, without ever typing the variable name again. That sounds indirect, and it is: pointers are how Go lets one part of a program reach into another part's data.
& and *Go uses the same star symbol for two related jobs, and beginners often mix them up. The table separates them.
| Symbol | Name | The question it answers | Example |
|---|---|---|---|
& | address-of | Where does this variable live? | &price gives a *int |
* in a type | pointer type | This variable holds an address | var ptr *int |
* before a name | dereference | What value is at that address? | *ptr is the int |
nil | no address | The pointer points at nothing | var ptr *int |
package main
import "fmt"
func main() {
price := 1250
ptr := &price
fmt.Println("price:", price)
fmt.Println("*ptr:", *ptr)
*ptr = 999
fmt.Println("price after *ptr = 999:", price)
}Read ptr := &price out loud as: ptr holds the address of price. The type of ptr is *int, which you read as "pointer to int". A pointer type is written as a star in front of the type it points at.
When you call a function, Go copies each argument into the function's own parameter. The function works on the copy, then the copy disappears. That is safe, and it is also why a function cannot change your variable by default.
If you want a function to change the caller's value, pass the address. The parameter receives a pointer, and writing through it reaches the original.
package main
import "fmt"
// addTenByValue receives a copy of n.
func addTenByValue(n int) {
n = n + 10
}
// addTenByPointer receives the address of n.
func addTenByPointer(n *int) {
*n = *n + 10
}
func main() {
total := 100
addTenByValue(total)
fmt.Println("after value call:", total)
addTenByPointer(&total)
fmt.Println("after pointer call:", total)
}Inside addTenByPointer, *n = *n + 10 means: read the int at this address, add ten, and store it back at the same address. The call site writes addTenByPointer(&total) because the function asks for an address, not an int.
Penny stores each expense in a struct. Passing a struct by value copies every field, which is fine for a small Expense but wasteful for a big struct. More importantly, a function that must edit an expense needs its address.
package main
import "fmt"
type Expense struct {
ID int
Cents int
}
// applyDiscount edits the expense it is given, so it needs the address.
func applyDiscount(expense *Expense) {
expense.Cents = expense.Cents - 100
}
func main() {
coffee := Expense{ID: 1, Cents: 450}
applyDiscount(&coffee)
fmt.Printf("expense #%d now costs %d cents\n", coffee.ID, coffee.Cents)
}Notice that expense.Cents works even though expense is a pointer. Go follows the pointer for you when you ask for a struct field. The long form (*expense).Cents is legal but nobody writes it by hand.
nil: The Pointer That Points NowhereA pointer that was never given an address holds the special value nil (Go has no null). var ptr *int declares a pointer whose value is nil. It compiles, it prints, and it is dangerous to use.
You will meet pointers in three everyday situations: a function edits a struct; a method changes its receiver (the next lesson); or a value is optional and missing means nil. Everywhere else, plain values are easier to read, and Go encourages them.
In the first program, add fmt.Println(ptr) and run it twice. You will see a hexadecimal address that changes between runs; it is the real memory address, and it is not something to hard-code. Then write a function func addCents(expense *Expense, cents int) that adds cents to an expense, call it with &coffee, and print the new total. Finally, change the parameter to expense Expense and watch the total stop changing.
Key takeaways
A pointer is a value that holds the address of another value.
&x takes the address of x; *p reads or writes the value at that address.
Function arguments are copies, so pass a pointer when a function must change the caller's value.
The zero value of a pointer is nil, and dereferencing nil panics.
Go lets you use a dot on struct pointers: expense.Cents means (*expense).Cents.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.