Values & References6 / 15
Up next

Pointers mutate the caller

package main

import "fmt"

// a *int lets the function change the caller's variable
func double(n *int) {
	*n *= 2
}

func main() {
	x := 5
	double(&x)
	fmt.Println(x) // 10
}
What you're solving

pass an address to change a value