This is a creation in Article, where the information may have evolved or changed.
Beginner go, when instantiating an object, make a bit dizzy, before learning PHP, need a new one between objects, but in go there are three ways, as follows
A:=new (user) b:=&user{}c:=user{}
As if these three methods can be achieved, what is the reason, the difference?
OK, take a look at the following example
Package Mainimport ("FMT") type user struct {id int ' 1123 '}func main () {A: = &user{} a.id = 111 B: = user{} b.id = 222 c: = new (user) C.id = 333 FMT. Println (A, B, c)}
After running the results are as follows
&{111} {222} &{333}
Now it's basically clear that the data returned by both methods new (user) and &user{} is the same, so what's the difference between these two types of data? What scenarios should we use?
Baidu a bit
&{111} returns a pointer to the instantiated object
{222} returns a type
Detailed further study is required