address operator
The & operator in Go, which takes the memory address of a variable and gives you a pointer to it.
In more detail
addTag(&status) passes a pointer to status so the function can change it. You can also write &Target{...} to create a value and get a pointer to it in one step. Only addressable values, such as variables and struct fields, can have their address taken.
Example
addTag(&status)Related terms
- pointer — A value that stores the memory location of another piece of data, so the program can follow it to that data.
- dereference — Following a reference or pointer to reach the value it points at.
- 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.
Taught in
- Pointers and Memory — Concurrent Systems Programming with Go