I'm pretty new to golang, and compiled languages in general, so please excuse my ignorance. In some code like this:
package main
import "fmt"
func assign() int {
return 1
}
func reference(foo *int) int {
*foo = 2
return 0
}
func main() {
var a, b int
a = assign()
reference(&b)
fmt.Println(a)
fmt.Println(b)
}
...what is the practical difference between assigning the value to a vs. passing b by reference?
In terms of real-world code, why does json.Unmarshal() require you to pass a pointer to your empty variable rather than just returning the Unmarshalled value so you can assign it to your variable?