Exam sample: why is this variable in C++ producing such an output?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points">Undefined Behavior and Sequence Points</a>  </p>
</blockquote>



<p>Working out the below code by hand:</p>

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

int func (int a, int b) {
    static int c = 1;
    return a + b * (c *= -1);
}

int main () {
    int a = 2, b = 3;
    int c = func(a, b);

    a *= a++;
    b *= ++b;

    printf("%d %d %d %d\n", a, b, c, func(a, b));
}
</code></pre>

<p>I calculate the variables in <code>printf()</code> to be as follows:</p>

<pre><code>a = 5, b = 16, c = -1, func(a, b) = -11
</code></pre>

<p>however my compiler tells me the last value is in fact 21.</p>

<p>Output:</p>

<pre><code>a = 5, b = 16, c = -1, func(a, b) = 21n
</code></pre>

<p>I'd calculate my value as <code>(16*-1) + 5</code></p>

<p>Can anyone tell me where I have gone wrong?</p>
