golang 指针在struct里的应用
package main import "fmt" type OBJ struct { A string B *int } func main() { var data int = 0 addr := &data obj1 := OBJ{ A: "aaa", B: addr, } obj2 := OBJ{ A: "bbb", B: addr, //与obj1的B指向了同一地址 } *(obj1.B) = 1 //用obj1修改data的值 fmt.Printf("value is %+v\n", obj1) fmt.Printf("value is %+v\n", obj2) fmt.Println(*(obj2.B)) //从obj2的B获取的值也变量了1 }
相关推荐
拉斯厄尔高福 2020-10-19
csdnyasin 2020-06-28
penkgao 2020-06-13
qscool 2020-06-12
fengjing81 2020-06-06
AaronPlay 2020-06-02
lynjay 2020-06-02
twater000 2020-05-29
徐建岗网络管理 2020-05-13
qingsongzdq 2020-05-07
jeonkc 2020-05-06
lynjay 2020-05-03
徐建岗网络管理 2020-05-03
shangs00 2020-04-27
xuguiyi00 2020-04-22
qscool 2020-04-18
GoatSucker 2020-04-11