title: How does cout's << operator work with regard to operator precedence?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5214611/unexpected-order-of-evaluation-compiler-bug">Unexpected order of evaluation (compiler bug?)</a>  </p>
  </blockquote>
  
  
  
  <p>I couldn't predict the output for this program :</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  int *p(int *a)
  {
      (*a)++;
      return a;
  }
  int main()
  {
      int i=0;
  
      cout&lt;&lt;i++&lt;&lt;" "&lt;&lt;(*p(&amp;i))++&lt;&lt;" "&lt;&lt;i++&lt;&lt;" "&lt;&lt;i&lt;&lt;endl;
      return 0;
  }
  </code></pre>
  
  <p>When compiled in vs2008, it outputs <code>3 2 0 4</code>.  Can anybody explain why it's not <code>0 2 3 4</code> ?</p>
  
  <p>Note: It works great if there is no function call to <code>p</code>.</p>
  
  <p>Thanks in advance!</p>