title: What is the correct answer for cout << a++ << a;?
body: <p>Recently in an interview there was a following objective type question.</p>
  
  <pre><code>int a = 0;
  cout &lt;&lt; a++ &lt;&lt; a;
  </code></pre>
  
  <p>Answers:</p>
  
  <p>a. 10<br>
  b. 01<br>
  c. undefined behavior</p>
  
  <p>I answered choice b, i.e. output would be "01".</p>
  
  <p>But to my surprise later I was told by an interviewer that the correct answer is option c: undefined.</p>
  
  <p>Now, I do know the concept of sequence points in C++. The behavior is undefined for the following statement:</p>
  
  <pre><code>int i = 0;
  i += i++ + i++;
  </code></pre>
  
  <p>but as per my understanding for the statement <code>cout &lt;&lt; a++ &lt;&lt; a</code> , the <code>ostream.operator&lt;&lt;()</code> would be called twice, first with <code>ostream.operator&lt;&lt;(a++)</code> and later <code>ostream.operator&lt;&lt;(a)</code>.</p>
  
  <p>I also checked the result on VS2010 compiler and its output is also '01'.</p>