知识卡片
指针间接读写同一对象
指针保存变量地址,&取得地址,*解引用访问该变量。传指针本身仍是值传递,但复制的是地址,因此函数可间接修改调用者的对象。未初始化指针的零值为nil;使用前须保证指向有效对象。它和把某个普通数值副本传入函数不同。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Go Language Foundations · 查看原书依据
A pointer stores the address of a variable: the location in memory where the value is stored. Every variable has an address, and using pointers allows us to indirectly read or update the value of their variables. Figure 3-1. The expression p := &a gets the address of a and assigns it to p. Retrieving
参考来源
- 位置:《Cloud Native Go》第03章《Go Language Foundations》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch03.xhtml)
- 结论依据:指针保存变量地址,&取得地址,*解引用访问该变量。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。
- 原始内容:A pointer stores the address of a variable: the location in memory where the value is stored. Every variable has an address, and using pointers allows us to indirectly read or update the value of their variables. Figure 3-1. The expression p := &a gets the address of a and assigns it to p. Retrieving