Code:#include <stdio.h> int main(void){ int x; x = 5; printf("x is %d\n", ++x++); //or... printf("x is %d\n", (++x)++); //or even printf("x is %d\n", ++(x++)); // !!! }
Code:#include <stdio.h> int main(void){ int x; x = 5; printf("x is %d\n", ++x++); //or... printf("x is %d\n", (++x)++); //or even printf("x is %d\n", ++(x++)); // !!! }
Why would it be useful if it was?
The reason the last one is not allowed is that the return value of postfix ++ is not an lvalue. You can't do that for the same reason that you can't do ++1.
The second one is just a sequence point issue. Two updates to the same variable without a SP in-between is undefined behaviour.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
What about the first one???The reason the last one is not allowed is that the return value of postfix ++ is not an lvalue. You can't do that for the same reason that you can't do ++1.
The second one is just a sequence point issue. Two updates to the same variable without a SP in-between is undefined behaviour.
WHO on earth is sequence point?? I haven't met this fella before
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*