why x = x++ incorrect and only x++ is used for incrementing a variable?

see http://discuss.codechef.com/questions/56506/nov-cookoff-2014-brackets-solution-problem
this was where i got an error in nov cook off and wondered why it was giving an error in online compiler and not on codeblocks .

It’s not incorrect.

You do not need to ask “duplicate” question, you can ask in thread you referenced…

Good advice for a beginner is: “Do not use something, you do not understand fully”. And this is not related only to this operators…

According to my tests, it works on ideone (http://ideone.com/SDs3yR ), which online compiler you meant?

As mentioned on SO, it’s undefined, so it may work in one compiler, but not in another…

  1. Undefined behaviour.
  2. If you are getting the result, that also depends on compiler. In different compiler, u will get different result.
  3. Reason: A variable cannot be modified more than once in any expression unless the modification is punctuated with a sequence point.
  4. Don’t try to operate more than once upon a variable in a single expression.
  5. There are 6 in Sequence points in standard C++. A sequence point guarantees that all the side effects of the previous expression are complete and no side effects from sub-sequence expression have been performed. Since i is modified more than once and read in this expression, the result is undefined.

thanks for the advice and help.

thanks for a good explanation.