title: Why in conditional operator (?:), second and third operands must have the same type?
body: <p>Why in <strong>conditional operator</strong>(<code>?:</code>), second and third operands must have the same type?</p>
  
  <p>My code like this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using std::cout;
  
  int main()
  {
      int a=2, b=3;
      cout &lt;&lt; ( a&gt;b ? "a is greater\n" : b );  /* expression ONE */
      a&gt;b? "a is greater\n" : b;               /* expression TWO */
  
      return 0;
  }
  </code></pre>
  
  <p>When compile it using g++, it issue an error:</p>
  
  <pre><code>main.cpp:7:36: error: operands to ?: have different types ‘const char*’ and ‘int’
  main.cpp:8:28: error: operands to ?: have different types ‘const char*’ and ‘int’
  </code></pre>
  
  <p>I wonder why they must have the same type?</p>
  
  <p><strong>(1)</strong> In my opinion, if <code>(a&gt;b)</code> is true, then the expression <code>( a&gt;b ? "a is greater\n" : b )</code>will return <code>"a is greater\n"</code> and <code>cout &lt;&lt; "a is greater\n"</code> will output that string;<br>
  otherwise the expression will return <code>b</code>, and <code>cout &lt;&lt; b</code> will output the value of b.</p>
  
  <p>But, unfortunately it is not like this. WHY?</p>
  
  <p><strong>(2)</strong> The second expression gets the same error.</p>
  
  <p><em>PS: I know, it is the standard who says it must be like this, but, why the standard say so?</em></p>