The short answer is that x = x + 1 cannot always be directly replaced with x++ (in terms of the search and replace operations), but any x++ appearance can be replaced with equivalent code that does not use the increment operator.
As written on the right side, a call to f(x = x + 1) conveys the incremental value of x , while a call to f(x++) fails; but you can easily fix it with f(x); x = x + 1; f(x); x = x + 1; .
You can even use x = (f(x), x + 1); although it may be harder to read.
The increment operator makes it easy to assign and increase a value on a single line, but you can choose whether the increment occurs before or after using the value:
x = 1; y = ++x; // y = 2, x = 2 z = x++; // z = 2, x = 3
With a simple assignment such as x = x + 1 , the value is always used after the increment occurs.
This is especially useful in pointer operations. For example, you can copy a zero-terminated string very briefly:
while ((*dest++ = *src++) != '\0') ;
This is a very common idiom, and experienced programmers will immediately recognize and understand it. So this is a very convenient shorthand, but you can always extend the code:
while (true) { *dest = *src; if (*dest == '\0') { break; } src + src + 1; dest + dest + 1; }
Although this gives the same result, much more effort is required for reading and understanding. In fact, I would expect an experienced programmer to wonder why the author didn’t just use a simpler version - was it inexperienced, or is there some kind of hidden difference?