C++ operator precedence in output stream
问题 int a = 1, b = 2; int c = a*b + b==0; // c = 0 cout << a*b + b==0; // outputs 4 c evaluates to 0 because the operator precedence of the * and + operators is higher than == as a result of which c essentially evaluates to (a*b+b)==0 which is false. Why does putting the same expression in a cout statement output 4? 回答1: Because the precedence of these operators are operator* > operator+ > operator<< > operator== . Then cout << a*b + b==0; is equivalent with (cout << ((a*b) + b)) == 0; . Then the