Values & References9 / 15
Up next

Pointer to a struct

package main

import "fmt"

type Point struct{ X, Y int }

func moveRight(p *Point) {
	// p.X is shorthand for (*p).X
	p.X++
}

func main() {
	p := Point{1, 2}
	moveRight(&p)
	fmt.Println(p.X)
}
What you're solving

field access auto-dereferences