logic ops,

V

vsgdp

bool a =false;
bool b=true;
cout << (a || b) && false;
cout.operator <<((a || b) && false);

The first cout outputs true. The second one false. Why not both false?
 
M

Marcus Kwok

vsgdp said:
bool a =false;
bool b=true;
cout << (a || b) && false;
cout.operator <<((a || b) && false);

The first cout outputs true. The second one false. Why not both false?

Order of operations. The first one does "cout << (a || b)" first, which
returns a reference to the stream (cout). Then it does "cout && false"
and discards the result.

It should do what you think if you add an extra set of parentheses:

cout << ((a || b) && false);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top