I have this code:
type countHolder struct {
count int
}
func main() {
a := &countHolder{1}
b := *a
a.count = 2
println(b.count)
}
I expected the output to be 2, but the output was 1.
My understanding was that:
-
a := &countHolder{1}
// a is pointer to struct with data starting at address x -
b := *a
// b now equals address x -
a.count = 2
// the struct stored at address x has its count value changed to 2
Where am I wrong? is b := *a
creating a copy of the struct?