mirror of
https://gitlab.com/djdietrick/docs
synced 2026-05-03 02:40:55 -04:00
578 B
578 B
Pointers
Pointers, like C++, hold memory addresses of a value. The zero value of a pointer is nil. Pointers are declared with *T which is a pointer to type T. The & operator creates a pointer to its operand. You can access the pointer value with * to get and set.
var p *int
i := 42
p = &i
fmt.Println(*p)
*p = 21
Structs
To access values of a struct you are referencing with a pointer, you can use the shorthand of the . operator to access the value.
type Vertex struct {
X int
Y int
}
p := &Vertex{1,2}
fmt.Println(p.Y)
p.X = 4