Q:

Explain whether the following program fragment is legal

0

Explain whether the following program fragment is legal.

std::cout << "The sum of " << v1;
<< " and " << v2;
<< " is " << v1 + v2 << std::endl;

If the program is legal, what does it do? If the program is not legal, why not? How would you fix it?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

The program is not legal. The operator `<<` is a member of `std::cout`, thus cannot be called without the object `std::cout`. Prepend the expression with `std::cout`.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now