My doubt is about the usage of Increment/Decrement Operators (++ and --) in C (Also in C++). Is it absolutely necessary to use ++ and -- in programs?
For example consider the code given below,
int x=10;
x++;
This can be easily replaced as follows,
int x=10;
x=x+1;
So is it necessary to use ++ and -- in practical programming? I am asking this for a particular reason. In my opinion they are one of the most confusing operators in C, forming expressions like *x++, ++*x, x++ + ++x etc. and causing thousands of errors each day.
Of course I know that a direct mapping between ++ and the Assembly Instruction INCR is possible. But I believe any decent compiler with some ability to optimize can replace x=x+1 with INCR x.
So in short my Question is "Is there any situation where x=x+1 can not replace x++ ?".
It might be very helpful if somebody can provide a piece of code which will not work in the absence of ++ or --.
Any suggestions? Thank You.