Go 指针相关操作
作者:互联网
Go指针相关操作
输出结果456
//null_interface.go package main import "fmt" type Image2 struct { name string } func (I *Image2) SetName() { I.name = "123" } func main() { image2 := Image2{} image2.name = "456" //image3 := &image2 //&image2相对于 image3 := Image2{} image3.name = image2.name image3 := Image2{} image3.name = image2.name image3.SetName() fmt.Println(image2.name) }
创建指针输出结果123
package main import "fmt" type Image2 struct { name string } func (I *Image2) SetName() { I.name = "123" } func main() { image2 := &Image2{} image2.name = "456" image2.SetName() fmt.Println(image2.name) }
标签:name,Image2,fmt,image3,image2,Go,操作,main,指针 来源: https://www.cnblogs.com/zhaoyingjie/p/15772393.html