25% off

Use code FUNCMAIN at checkout for 25% off all premium courses.

Get started →

Interactive Go · Lesson

Pointers

A pointer holds the memory address of a value rather than a copy of it. Two operators do the work:

  • &x takes the address of x.
  • *p dereferences the pointer p — reading or writing the value it points at.
hp := 100
p := &hp     // p points at hp
*p = 80      // changes hp through the pointer
fmt.Println(hp) // 80

Pointers are how a function changes a caller’s variable instead of a copy — exactly what pointer receivers did in the last lesson.

Your Quest

powerUp takes a *int and increments it. Call it with the address of level, then print level.

Expected output:

6

Hint

Pass &level to powerUp, i.e. powerUp(&level), then fmt.Println(level).

Additional Scrolls of Wisdom