I just started to learn the golang.
I found the &
operator behaves differently for simple type and struct.
For simple type,
&
returns an address.For struct, it returns something else.
Code:
package main
import "fmt"
type person struct {
name string
age int
}
func main() {
s1 := "abc"
fmt.Println("s1 address =", &s1)
s2 := person{"Sam", 55}
fmt.Println("s2 address = ", &s2)
}
Output:
[ `hello` | done: 79.0079ms ]
s1 address = 0xc04203c1e0
s2 address = &{Sam 55} <======== What's this? And why not some address like above?
Again, is this design a have-to
or a happen-to
?