Values & References1 / 15
Up next

Go passes by value

package main

import "fmt"

// n is a copy; changing it doesn't affect the caller
func tryDouble(n int) {
	n *= 2
}

func main() {
	x := 5
	tryDouble(x)
	fmt.Println(x) // still 5
}
What you're solving

a copy is handed to the callee