The go language is no more than other languages, and in a struct, it has no constructors and does not have to be assigned or error-free.
Like what:
struct { string ageint}func main () { var P Student FMT. Println ("Theperson'snameis", p.name) FMT. Println ("the person'snameis", P.age)}
This is why, because when you name a type, string defaults to NULL, and the int type defaults to 0,float64, which defaults to 0.0.
There are several ways to use it when initializing:
The first type:
var P Student " Huang " fmt. Println ("Theperson'snameis", p.name) FMT. Println ("the person'snameis", P.age)
The second type, direct:
var P Student = student{"Huang"to FMT. Println ("Theperson'snameis", p.name) FMT. Println ("the person'snameis", P.age)
The third type:
New (person)
Note that the third new word represents a pointer.
The initialization of a struct in the go language.