++( x + 5 ) vs ++(x)

Hello!

the syntax :

1
2
int x = 2;
++( x + 5 );


will not compile because "there is no l-value." I think I understand this. When it tries to evaluate x + 5, you end up with a constant, and you can't use the ++ operator on a constant.

what about

1
2
int x = 2;
++( x );


why does this compile ok? Is it because nothing is being done to x inside the parenthesis so it still thinks its an l-value? Or does the compiler just ignore the parenthesis in this case?

Thanks for the info!
++ requires one operand, i suppose. And yes, i think the second variant is ok, 'coz there's only a variable.
In C++:

An lvalue is any expression that can appear on the left-hand side of an assignment operator.
An rvalue is any expression that can appear on the right-hand side of an assignment operator.

operator++ requires its operand to be an lvalue. x + 5 is not an lvalue; you could not, for
example, write this line of code:

x + 5 = y;
Thank you for you help!! :D
Topic archived. No new replies allowed.