09.01-struct
type Circle struct {
x float64
y float64
r float64
}type Circle struct {
x, y, r float64
}初始化
var c Circlec := new(Circle)c := Circle{x: 0, y: 0, r: 5}c := Circle{0, 0, 5}欄位
Last updated
type Circle struct {
x float64
y float64
r float64
}type Circle struct {
x, y, r float64
}var c Circlec := new(Circle)c := Circle{x: 0, y: 0, r: 5}c := Circle{0, 0, 5}Last updated
fmt.Println(c.x, c.y, c.r)
c.x = 10
c.y = 5func circleArea(c Circle) float64 {
return math.Pi * c.r*c.r
}c := Circle{0, 0, 5}
fmt.Println(circleArea(c))func circleArea(c *Circle) float64 {
return math.Pi * c.r*c.r
}c := Circle{0, 0, 5}
fmt.Println(circleArea(&c))