Golang basics struct and new() keyword

前端 未结 3 1702
Happy的楠姐
Happy的楠姐 2021-02-01 01:54

I was learning golang, and as I was going through the chapter that describes Structures, I came across different ways to initialize structures.

p1 := passport{}         


        
3条回答
  •  一生所求
    2021-02-01 02:52

    All the new keyword does is basically create a instance of the type you want. However instead of returning the plain declaration of the type, it references it and return the acutal memory address of that type in the program process heap.

提交回复
热议问题