作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
{
int a =2,b=2,c=0;
c = a+(b++);
printf("output:c=%d\tb=%d\n",c,b);
}
output: c=4 b=3
这里如何输出c = 4,我的理解是c=5,谁能解释一下吗?
最佳答案
因为++i
和i++
之间是有区别的!
前缀/后缀
++i // `Prefix` gets incremented `before` it get's used (e.g. in a operation)
i++ // `Postfix` gets incremented `after` it get's used (e.g. in a operation)
这就是为什么 c 是 4!
如果将 b++
更改为 ++b
,则 c 得到 5!
另请参阅:
What is the difference between prefix and postfix operators?
关于c = a+(b++); printf ("output:c=%d\tb=%d\n",c,b); = 4,3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27027603/
我是一名优秀的程序员,十分优秀!