previous | start | next

Return Type of operator<<

Consider the cout expression:

int main()
{
  int x = 5;
  int y = 3*x + 1;

  cout << "y = " << y;
  cout << endl;

}
     

There are two << operators. They evaluate from left to right. So the expression evaluates as if it were parenthesized like this:

  (cout << "y = ") << y;
     

The value of parenthesized expression is the left operand of the second << operator.

What is the value of the parenthesized expression

(cout << "y = ")  
     


previous | start | next