When I use i++++ give compile error :
for (int i=1;i<=10;i++++) {} //a.cpp:63: error: lvalue required as increment operand
or
int i = 0;
i++++; // a.cpp:65: error: lvalue required as increment operand
but when I use ++++i is working. Anybody explain me why ++++i regular but i++++ not regular?
Thanks.
Since type of x is built-in primitive type, both expressions invoke undefined behaviour, as both attempt to modify the same object twice between two sequence points.
Don't do either of them.
Read this FAQ :
Undefined behavior and sequence points
However if the type of x is a user-defined type and you've overloaded operator++ for both expressions, then both would be well-defined.
For this, see this topic to know the explanation and details:
Undefined behavior and sequence points reloaded
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With