找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 302|回复: 1

Question4.3:Does *p++ increment p, or what it points to?

[复制链接]

210

主题

371

回帖

0

积分

管理员

积分
0
发表于 2013-7-2 16:16:35 | 显示全部楼层 |阅读模式
Q: Does *p++ increment p, or what it points to?
A: The postfix ++ and -- operators essentially have higher precedence than the prefix unary operators. Therefore, *p++ is equivalent to
(p++); it increments p, and returns the value which p pointed to before p was incremented. To increment the value pointed to by p, use (*p)++ (or perhaps ++*p, if the evaluation order of the side effect doesn't matter).     

210

主题

371

回帖

0

积分

管理员

积分
0
 楼主| 发表于 2013-7-2 16:27:05 | 显示全部楼层
问题:对于*p++是增加变量p还是它所指向的?
回答:对于后缀++和--运算符本质上是比前缀的一元运算符的优先级要高的。因此,*p++是与*(p++)等价的,并且返回的值是在增加变量p之前的p所指向的值的。要增加p所指向的值,则使用(*p)++(如果求值的顺序的副作用不是特别重要的话,也可以使用++*p)。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

果子博客
扫码关注微信公众号

Archiver|手机版|小黑屋|风叶林

GMT+8, 2026-2-1 04:42 , Processed in 0.192076 second(s), 20 queries .

Powered by 风叶林

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表