preFIX /后缀增量 [英] prefix/suffix increment

查看:157
本文介绍了preFIX /后缀增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能重复:结果
  后增量和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 suffix i++ operators affect the order in which the statement is evaluated. With the prefix ++i, the value of i is incremented, and that is what is used. But with the suffix i++, the original value of i is used, and then it is incremented for anything following that line.

这篇关于preFIX /后缀增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆