知识卡片
函数参数按值传递
Go函数可返回多个值,也可递归调用。参数传入的是值的副本;指针、切片、映射等值仍可能间接引用共享对象,因此修改所指对象可能被调用者观察到,但给局部参数重新赋值不会自动替换调用者变量。必须区分值本身和它引用的数据。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Go Language Foundations · 查看原书依据
Typically, function parameters are passed by value: when a function is called it receives a copy of each parameter, and changes made to the copy by the function don’t affect the caller. However, pointers contain a reference to a value, rather than the value itself, and can be used by a receiving function to indirectly
参考来源
- 位置:《Cloud Native Go》第03章《Go Language Foundations》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch03.xhtml)
- 结论依据:Go函数可返回多个值,也可递归调用。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。
- 原始内容:Typically, function parameters are passed by value: when a function is called it receives a copy of each parameter, and changes made to the copy by the function don’t affect the caller. However, pointers contain a reference to a value, rather than the value itself, and can be used by a receiving function to indirectly