I have a nested struct. I want to update it inside a method. For some reason, the update doesn't take place.
package main
import "fmt"
type B struct {
c int
}
type A struct {
b B
}
func (a A) updateB(n int) {
a.b.c = n
}
func main() {
a := A{b: B{c: 5}}
fmt.Println(a)
a.updateB(42)
fmt.Println(a)
}
The output I get is
{{5}}
{{5}}
In most languages, I'd expect it to be updated. Is this some special Go behavior? How does one go about updating nested structs in Go?