Magic with writing increment and decrement expression in c/c++
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/949433/could-anyone-explain-these-undefined-behaviors-i-i-i-i-i-etc">Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc&hellip;)</a><br>
  <a href="http://stackoverflow.com/questions/7232840/confused-about-how-unary-operations-result-in-this-output">Confused about how unary operations result in this output</a></p>
</blockquote>



<p>I have a simple program:</p>

<pre><code>#include &lt;iostream&gt;

int main( int argc, char* argv[] )
{
        int a = 0;
    std::cout &lt;&lt; ++a &lt;&lt; a++ &lt;&lt; a++;
    return 0;
}
</code></pre>

<p>The result of running this code is:
310</p>

<p>Why? I expect the following result: 112 ?</p>

<p>This code is running similar:</p>

<pre><code>#include &lt;stdio.h&gt;

    int main( int argc, char* argv[] )
    {
        int a = 0;
        printf( "%d %d %d", ++a, a++, a++ );
        return 0;
    }
</code></pre>

<p>result: 3 1 0</p>
