I am passing a struct to a function by reference.
I was expecting if I define and change the struct inside the function I can get the new value outside.
But it is not happening.
Can anyone explain why?
package main
import "fmt"
func intbyRef(i *int) {
*i = 10
}
type ttt struct {
a int
}
func change(t *ttt) {
var p ttt = ttt{7}
fmt.Println(p)
t = &p
}
func main() {
i := 1
var t *ttt
fmt.Println(i)
fmt.Println(t)
change(t)
intbyRef(&i)
fmt.Println(i)
fmt.Println(t)
}
You can try the code in here: https://play.golang.org/p/I-GIdIZ9c6