Solution Review: Anonymous Struct
This lesson discusses the solution to the challenge given in the previous lesson.
package mainimport "fmt"type C struct { // structx float32int // int type anonymous fieldstring // string type anonymous field}func main() {c := C{3.14, 7, "hello"} // making struct via literal expressionfmt.Println(c.x, c.int, c.string) // output: 3.14 7 hellofmt.Println(c) // output: {3.14 7 hello}}
Get hands-on with 1400+ tech skills courses.