Unary operators have the highest precedence. As the ++ and -- operators form statements, not expressions, they fall outside the operator hierarchy. As a consequence, statement *p++ is the same as (*p)++.
其实也并不是那么显然的事。
`Unary operators have the highest precedence. As the ++ and -- operators form statements, not expressions, they fall outside the operator hierarchy. As a consequence, statement *p++ is the same as (*p)++.`
如果没有上述保底,也许就是`*(p++)`了。
其实也并不是那么显然的事。
`Unary operators have the highest precedence. As the ++ and -- operators form statements, not expressions, they fall outside the operator hierarchy. As a consequence, statement *p++ is the same as (*p)++.`
如果没有上述保底,也许就是`*(p++)`了。
get
打卡
mark
Get
其实也并不是那么显然的事。
Unary operators have the highest precedence. As the ++ and -- operators form statements, not expressions, they fall outside the operator hierarchy. As a consequence, statement *p++ is the same as (*p)++.
如果没有上述保底,也许就是
*(p++)
了。打卡
go不支持直接对指针进行运算,所以不用考虑你这种情况,这大概就是大道至简吧。
谁要这么写代码会被老板打死。返回int,却return一个指针;函数有返回值调用的时候却没有承接的变量。(golang码农求职)
有没有一种可能:作者的用意涵盖了开发中常用的
struct
和*struct
,只是为了突出问题重点,用了int
和*int
作为演示题目代码可以运行并输出(go1.18),就算需要加括号,应该也是
(*p)++
这题不能想复杂了
打卡
打卡
mark
打卡。。。。。。
mark
打卡
1
*(p++) 这种写法编译不通过的
关键是,程序能编译通过,还能运行起来
仔细看:
*int
代表类型。*p
代表解引用。incr(&p) 我说的是这里,函数回来的值,没有变量承接
mk
打卡学习
2
*p++
mark
mk
mark
1
mark
mark
mark
打卡
mark
Dereference operator 解引用
mark
mark
mark
加上*取值符号不就是return了一个int值,并不是指针啊
2
mark
func incr(p int) int { p++ return *p }
func main() { p :=1 incr(&p) fmt.Println(p) }
// 结果: 2
mark
mark