What is i+++ increment in c++

半城伤御伤魂 提交于 2019-12-18 13:39:22

问题


can anyone tell me what is the process of i+++ increment in c++.


回答1:


It is a syntax error.

Using the maximum munching rule i+++ is tokenized as:

i ++ +

The last + is a binary addition operator. But clearly it does not have two operands which results in parser error.

EDIT:

Question from the comment: Can we have i++++j ?

It is tokenized as:

i ++ ++ j

which again is a syntax error as ++ is a unary operator.

On similar lines i+++++j is tokenized by the scanner as:

i++ ++ + j

which is same as ((i++)++) + j which again in error as i++ is not a lvalue and using ++ on it is not allowed.




回答2:


i+++; will not compile. There is no operator +++ in C++.

i+++j, on the other hand, will compile. It will add i and j and then increment i. Because it is parsed as (i++)+j;




回答3:


if you mean i++ then its incrementing the value of i once its value has been read. As an example:

int i = 0;   // i == 0
int j = i++; // j == 0, i == 1


来源:https://stackoverflow.com/questions/5236706/what-is-i-increment-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!