What is the correct answer for cout << c++ << c;?
<p>Recently in an interview there was a following objective type question.</p>

<pre><code>int c = 0;
cout &lt;&lt; c++ &lt;&lt; c;
</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; c++ &lt;&lt; c</code> , the <code>ostream.operator&lt;&lt;()</code> would be called twice, first with <code>ostream.operator&lt;&lt;(c++)</code> and later <code>ostream.operator&lt;&lt;(c)</code>.</p>

<p>I also checked the result on VS2010 compiler and its output is also '01'.</p>
