Possible Duplicate:
Why is ++i considered an l-value, but i++ is not?
In C++ (and also in C), if I write:
++x--
++(x--)
i get the error: lvalue required as increment operand
However (++x)-- compiles. I am confused.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Post- and pre-increment operators only work on lvalues.
When you call
++ithe value ofiis incremented and theniis returned. In C++ the return value is the variable and is an lvalue.When you call
i++(ori--) the return value is the value ofibefore it was incremented. This is a copy of the old value and doesn’t correspond to the variableiso it cannot be used as an lvalue.Anyway don’t do this, even if it compiles.