addressable value
A value in memory that Go can take the address of with &, such as a variable, a struct field or a slice element.
In more detail
Temporary results, such as a function's return value or a map element, are not addressable. When you call a pointer-receiver method on an addressable variable, Go takes the address for you, so c.Add() works on a Counter variable.
Example
c := Counter{}
c.Add() // Go passes &cRelated terms
- address operator — The & operator in Go, which takes the memory address of a variable and gives you a pointer to it.
- pointer receiver — A method receiver declared as a pointer, such as (c *Counter), which lets the method change the original value rather than a copy.
- method — A function that belongs to an object or type and is called on a value of it, as in name.upper().
Taught in
- Structs and Methods — Concurrent Systems Programming with Go