can anyone tell me what is the process of i+++ increment in c++.
Asked
Active
Viewed 1.2k times
3
-
You really mean three plus signs and not two? – John Mar 08 '11 at 18:32
-
@john: I meant +++ and I'm fully aware of conventional c++ and increment operators. – Biswanath Chowdhury Mar 08 '11 at 19:10
-
@BC: That's cool. Just checking. – John Mar 08 '11 at 19:14
3 Answers
20
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.

codaddict
- 445,704
- 82
- 492
- 529
17
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
;

Armen Tsirunyan
- 130,161
- 59
- 324
- 434
-
2Also note that it'll throw away the result of `i+j` unless you assign it as well. – Mark B Mar 08 '11 at 18:34
-
@Mark B: If I were you, I'd use the term `throw` with caution as far as C++ is concerned. Took me a couple of seconds to understand you aren't talking about exceptions :) – Armen Tsirunyan Mar 08 '11 at 18:38
-
actually I am talking about 3 "+" signs that is +++, and want to know their significance. – Biswanath Chowdhury Mar 08 '11 at 19:04
-
there is no question about exceptions or SEH handlers, I was just asking about the "munching rule" which of of u have specified. You mentioned the first line , which I think I am aware and was naive, but thnx for your replies. – Biswanath Chowdhury Mar 08 '11 at 19:22
1
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

langerra.com
- 779
- 3
- 8