Why the conditional expressions need a bracket

I'm a newbie of C++, the following conditional expressions after "cout" need a bracket, otherwise them would occur with running errors. Any help would be great!

1
2
3
4
5
6
7
8
9
#include<iostream>
using namespace std;
int main()
{
	cout<<"1||0&&1&&0="<<(1||0&&1&&0)<<endl;
	cout<<"!1+2>1="<<(!1+2>1)<<endl;
	cout<<"0&&!2+5||1&&!(2+!0)="<<(0&&!2+5||1&&!(2+!0))<<endl;
	return 0;
}
Last edited on
The left shift and right shift operators << and >> have a higher precedence than
the relational operators >, >=, < and <= and the logical operators && and ||.
http://en.cppreference.com/w/cpp/language/operator_precedence

So, std::cout << a || b is parsed as ( std::cout << a ) || b
and std::cout << a < b is parsed as ( std::cout << a ) < b
Thanks for JL Borges's hlep, got it!
Topic archived. No new replies allowed.