Hi,
I have a struct and a method that’s working on the structs reference. The pointer address is changing every time I call the method. Why is like that?
Code
package main
import "k8s.io/contrib/compare/Godeps/_workspace/src/github.com/emicklei/go-restful/log"
type Whatever struct{
Name string
}
func (whatever *Whatever) GetNameByReference() (string) {
log.Printf("Whatever.GetNameByReference() memory address: %v", &whatever)
return whatever.Name
}
func evaluateMemoryAddressWhenNotWritingAnything() {
whatever := Whatever{}
whatever.GetNameByReference()
whatever.GetNameByReference()
whatever.GetNameByReference()
}
func main() {
evaluateMemoryAddressWhenNotWritingAnything()
}
Output:
[restful] 2017/01/18 09:30:18 log.go:30: Whatever.GetNameByReference() memory address: 0xc420034020
[restful] 2017/01/18 09:30:18 log.go:30: Whatever.GetNameByReference() memory address: 0xc420034030
[restful] 2017/01/18 09:30:18 log.go:30: Whatever.GetNameByReference() memory address: 0xc420034038
```