Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't have the time to write up a detailed description of the <em>differences</em> between C++, C, C# and Java. I will merely say that the C# behaviour of the pre and post increment operators is <strong>fully specified</strong> (in single-threaded scenarios; if you want to know about its atomicity, guarantees about observations of read and write orders in multi-processor weak memory models and so on, you're on your own to do that research.) It is not fully specified in C and C++; a compiler has broad lattitude to do whatever it pleases with re-ordering side effects. I have never used Java so I'm not going to hazard a guess as to what Java does.</p> <p>For more information on what C# does you should read the C# specification. For a short take on it, read my answer to this question:</p> <p><a href="https://stackoverflow.com/questions/3346450/c-what-is-the-difference-between-i-and-i/3346729#3346729">What is the difference between i++ and ++i?</a></p> <p>For an even shorter take:</p> <p>Subexpressions in a C# expression are logically grouped by precedence and associativity, and then evaluated from <strong>left to right</strong> regardless. (So for example, A() + B() * C() evaluates A(), then B(), then C(). The fact that the multiplication "comes before" the addition is irrelevant; the subexpressions are always evaluated left to right.) </p> <p>If the evaluation of a subexpression causes a side effect because of a pre or post increment subexpression then the side effect happens <em>immediately before</em> the result is produced.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload