Im a beginner here at go
but i have a question:
I have the following code:
package lab
import (
"fmt"
"math"
)
type Circle struct {
x float64
y float64
r float64
}
func (c *Circle) area() float64 {
return math.Pi * c.r * c.r
}
func StructCode() {
c := Circle{1,2,5}
fmt.Println("struct addr",c)
fmt.Println("Circle",c.area())
}
My question is, the Circle area function
takes a Circle Pointer
and returns the area. Based on this. why when i print the struct it doesnt show a memory address, but shows &{1 2 5}
instead . It takes a pointer for the area function but the c circle
isn't printing as a pointer (in which i imagine it would have printed a memory address being a circle pointer
)
UPDATE
Unless possibly &{1 2 5}
is actually the reference?
SECOND UPDATE
I was able to get it doing this:
c := Circle{1,2,5}
p := &c
fmt.Printf("%p",p)
// returns 0xc042052340
However my question now is, why can I pass c.area()
instead of p.area()
as area function of circle requires a pointer: