anonymous_struct.go 233 B

123456789101112131415
  1. package main
  2. import "fmt"
  3. type C struct {
  4. x float32
  5. int
  6. string
  7. }
  8. func main() {
  9. c := C{3.14, 7, "hello"}
  10. fmt.Println(c.x, c.int, c.string) // output: 3.14 7 hello
  11. fmt.Println(c) // output: {3.14 7 hello}
  12. }