Advertisement
cwchen

[Go] Nested struct.

Sep 19th, 2017
635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.31 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "math"
  6. )
  7.  
  8. type Point struct {
  9.     x float64
  10.     y float64
  11. }
  12.  
  13. type Circle struct {
  14.     r float64
  15.     p Point
  16. }
  17.  
  18. func main() {
  19.     c := Circle{r: 5.0, p: Point{x: 3.0, y: 4.0}}
  20.  
  21.     fmt.Println(c.p.x)
  22.     fmt.Println(c.p.y)
  23.  
  24.     circumstance := 2 * math.Pi * c.r
  25.     fmt.Println(circumstance)
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement