Go · Stage 7 – Structuring Data · Lesson 44 of 64

Pointers

Understand a pointer slowly as an address, not the value at that address.

Go code

number := 10
pointer := &number
fmt.Println(*pointer)
Line-by-line explanation
  1. Number stores 10.
  2. The ampersand takes number’s address.
  3. Pointer stores that address.
  4. The star follows the address to read the value.
Expected output
10

This is the expected result.

The & operator takes an address. The * operator follows a pointer to its value; this is called dereferencing.