Hello, I’m a student majoring CE who is studying Golang.
I have a question about my code.
the function foo()'s results keep changing each calling.
I can’t understand why the address of STRUCT str’s s keeps changing.
is there anyone about this situation?
import "fmt"
type str struct {
s int
t int
r int
}
type str2 struct {
s string
t string
r string
}
type inter_face interface {
foo()
}
func (s str) foo() {
fmt.Println("Print")
}
func (s str2) foo() {
fmt.Printf("%v\t%T\t\t\n", &s.r, s)
}
func main() {
var i inter_face
a := str{
s: 100,
t: 1000,
r: 10000,
}
b := str2{
s: "string",
t: "string type",
r: "string bool",
}
i = a
i.foo()
i.foo()
i = b
i.foo()
i.foo()
i.foo()
i.foo()
i.foo()
i.foo()
}