以下功能有什么區(qū)別?func DoSomething(a *A){ b = a}func DoSomething(a A){ b = &a}
2 回答

白板的微信
TA貢獻1883條經(jīng)驗 獲得超3個贊
func DoSomething(a *A) { // a is a pointer to given argument of type A
b = a // b is a copy of a, which is also the same pointer
// this is useful to change the given object directly
}
func DoSomething(a A) { // a is a copy of the given object type A
b = &a // b is the pointer of a
}
請記住,指針是一個保存內(nèi)存地址的變量。
- 2 回答
- 0 關(guān)注
- 192 瀏覽
添加回答
舉報
0/150
提交
取消