preFIX /后缀增量 [英] prefix/suffix increment
问题描述
可能重复:结果
后增量和pre增量概念?
块引用>任何一个可以明确地解释preFIX增量从后缀增量有何不同?
也有人可以解释为什么这个输出6?
I = 1;
COUT<< ++ 1 + + +我;也是为什么这给了4
I = 1;
COUT<< ++我+ I ++;和为什么会产生如此
I = 0;
COUT<< (我++ ||我++)
解决方案在preFIX
++我
和后缀我++
运营商影响该语句计算顺序。随着preFIX++我
,i的值
递增,那就是使用什么。但随着后缀我++
,的原始值i
使用,然后是继该行增加任何东西Possible Duplicate:
Post Increment and Pre Increment concept?Can any one explicitly explain how prefix increment differs from suffix increment?
also can someone explain why this output 6?
i=1; cout << ++i + ++i;
also why this gives 4
i = 1; cout << ++i + i++;
and why this produces true
i = 0; cout << (i++ || i++)
解决方案The prefix
++i
and suffixi++
operators affect the order in which the statement is evaluated. With the prefix++i
, the value ofi
is incremented, and that is what is used. But with the suffixi++
, the original value ofi
is used, and then it is incremented for anything following that line.这篇关于preFIX /后缀增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!