以下功能有什么区别?func DoSomething(a *A){ b = a}func DoSomething(a A){ b = &a}
2 回答
白板的微信
TA贡献1883条经验 获得超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
}
请记住,指针是一个保存内存地址的变量。
- 2 回答
- 0 关注
- 172 浏览
添加回答
举报
0/150
提交
取消