知识卡片

普通读书笔记卡 · 4545.g.8.h

函数参数按值传递

理解等级:中级

Go函数可返回多个值,也可递归调用。参数传入的是值的副本;指针、切片、映射等值仍可能间接引用共享对象,因此修改所指对象可能被调用者观察到,但给局部参数重新赋值不会自动替换调用者变量。必须区分值本身和它引用的数据。

这张卡片看不懂?

已有反馈 · 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