bool operator ++ and —

It comes from the history of using integer values as booleans. If x is an int, but I am using it as a boolean as per if(x)… then incrementing will mean that whatever its truth value before the operation, it will have a truth-value of true after it (barring overflow). However, it’s impossible to predict … Read more

Output of multiple post and pre increments in one statement [duplicate]

The results are undefined. You’re modifying a variable more than once in an expression (or sequence point to be more accurate). Modifying a variable more than once between sequence points is undefined, so don’t do it. It might be your compiler, for this particular case decides to evalate ++i + ++i as increment the last … Read more

Pre-incrementation vs. post-incrementation

Pre- or post-incrementing do not magically delay things until later. It’s simply inline shorthand. // pre-increment $var = 5; print(++$var); // increments first, then passes value (now 6) to print() // post-increment $var = 5; print($var++); // passes value (still 5) to print(), then increments Now let’s look at a loop. for ($i = 0; … Read more

Java increment and assignment operator [duplicate]

No, the printout of 10 is correct. The key to understanding the reason behind the result is the difference between pre-increment ++x and post-increment x++ compound assignments. When you use pre-increment, the value of the expression is taken after performing the increment. When you use post-increment, though, the value of the expression is taken before … Read more