ch2/ch2-03 #207
Replies: 13 comments 1 reply
-
|
不错 |
Beta Was this translation helpful? Give feedback.
-
|
Good |
Beta Was this translation helpful? Give feedback.
-
|
打卡,看这篇有点累 |
Beta Was this translation helpful? Give feedback.
-
|
打卡,一个个关卡一章章学 |
Beta Was this translation helpful? Give feedback.
-
|
打卡,终于理解了*x和&x的区别。 |
Beta Was this translation helpful? Give feedback.
-
|
let`s go |
Beta Was this translation helpful? Give feedback.
-
|
“由于new只是一个预定义的函数,它并不是一个关键字,因此我们可以将new名字重新定义为别的类型。” |
Beta Was this translation helpful? Give feedback.
-
|
每次循环的开始会创建临时变量t 这句话有点歧义,其实在for循环只会创建并初始化一次,在每一轮循环时会执行t += res |
Beta Was this translation helpful? Give feedback.
-
|
1 |
Beta Was this translation helpful? Give feedback.
-
|
打卡,指针看的有点晕了 |
Beta Was this translation helpful? Give feedback.
-
|
生命周期:从每个包级的变量和每个当前运行函数的每一个局部变量开始,通过指针或引用的访问路径遍历,是否可以找到该变量。 |
Beta Was this translation helpful? Give feedback.
-
func incr(p *int) int {
*p++ // 非常重要:只是增加p指向的变量的值,并不改变p指针!!!
return *p
}
v := 1
incr(&v) // side effect: v is now 2
fmt.Println(incr(&v)) // "3" (and v is 3)
"每次我们对一个变量取地址,或者复制指针,我们都是为原变量创建了新的别名。例如,*p就是变量v的别名。"
我个人觉得这里对别名的认知是错误的,因为指针变量p与变量v本身都会有自己的内存地址,它们是两个独立的空间。而别名的意思更多是两个变量名指向同一个内存地址,两个变量名共用一个内存空间,才叫做别名。
|
Beta Was this translation helpful? Give feedback.
-
|
nice |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
ch2/ch2-03
中文版
https://golang-china.github.io/gopl-zh/ch2/ch2-03.html
Beta Was this translation helpful? Give feedback.
All reactions