Home Segments Index Top Previous Next

78: Mainline

On the other hand, the assignment operator has precedence lower than that of the output operator. Accordingly, the parentheses are essential in the following program.

#include  
main ( ) { 
  int volume; 
  cout << "The volume of the box car is "; 
  cout << (volume = 11 * 9 * 40); 
  cout << endl; 
  // Statements using the volume variable go here 
} 

If you wrote cout <<volume = 11 * 9 * 40;, C++ would try to make sense of the statement as though you had written (cout <<volume) = 11 * 9 * 40;, which makes no sense.