concept memory address in category go

appears as: memory address, memory addresses
Get Programming with Go

This is an excerpt from Manning's book Get Programming with Go.

The address operator (&) provides the memory address of a value. The reverse operation is known as dereferencing, which provides the value that a memory address refers to. The following listing dereferences the address variable by prefixing it with an asterisk (*).

Listing 26.2. Dereference operator: memory.go
answer := 42
fmt.Println(&answer)       #1

address := &answer
fmt.Println(*address)      #2

In the preceding listing and in figure 26.1, the address variable holds the memory address of answer. It doesn’t hold the answer (42), but it knows where to find it.

It prints 42 because the memory address (&) is dereferenced (*) back to the value.

  • Pointers store memory addresses.
  • The address operator (&) provides the memory address of a variable.