Re:Why 1 && 2 == 2
by pbsd on Thursday July 18, 2013 @10:07PM
(#6067903)
In C++, << has higher precedence than &&, so in effect what is being done is
(cout << 1) && 2;
...which is not an error, since the result of operator<< is an std::ostream, which is convertible to bool. Therefore operator&&(bool, bool) is invoked but the result is, of course, discarded.
Disambiguating the expression with parentheses should output 1 in every case.
Disambiguating the expression with parentheses should output 1 in every case.