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.
#includemain ( ) { 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.