title: When does postincrement i++ get executed?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points">Undefined Behavior and Sequence Points</a>  </p>
  </blockquote>
  
  
  
  <p>In C++ on a machine code level, when does the postincrement++ operator get executed?</p>
  
  <p>The <a href="http://cppreference.com/wiki/language/operator_precedence" rel="nofollow noreferrer">precedence table</a> indicates that postfix++ operators are level 2:  which means in</p>
  
  <pre><code>int x = 0 ;
  int y = x++ + x++ ;  // ans: y=0
  </code></pre>
  
  <p>The postfix ++'s execute <em>first</em>.</p>
  
  <p>However, it would seem that the logical operation of this line is the addition happens first (0+0), but how does that happen?</p>
  
  <p>What I imagine, is the following:</p>
  
  <pre><code>// Option 1:
  // Perform x++ 2 times.
  // Each time you do x++, you change the value of x..
  // but you "return" the old value of x there?
  int y = 0 + x++ ;  // x becomes 1, 0 is "returned" from x++
  
  // do it for the second one..
  int y = 0 + 0 ;  // x becomes 2, 0 is "returned" from x++... but how?
  // if this is really what happens, the x was already 1 right now.
  </code></pre>
  
  <p>So, the other option is although x++ is higher on the precedence table that x + x, the code generated due to x++ is inserted <em>below</em> the addition operation</p>
  
  <pre><code>// Option 2:  turn this into
  int y = x + x ; // 
  x++ ;
  x++ ;
  </code></pre>
  
  <p>That second option seems to make more sense, but I'm interested in the order of operations here. Specifically, <em>when does x change</em>?</p>