+ 2
Is true && false == 1?
Still not cleared on this https://code.sololearn.com/cEvv139DcEns/?ref=app
11 Respuestas
+ 2
if anyone noticed while using logical operator for evaluation we always use them in parentheses such as if (x<y).
use this:
cout<<(true&&false);
ur result will be 0 as expected.
+ 4
I think in int and bool got right output rather cout also give correct output
look in cout first call true then &&false thats why output is 1 as true value
You can check this as cout << "but if u directly output true&&false u get "<< false&&true ;
now output is 0 as value of false..
+ 3
false && false -> false
false && true -> false
true && false -> false
true && true -> true
+ 3
In the case of cout, operator precedence is the issue.
cout << "but if u directly output true&&false u get "<< true&&false;
is equivalent to
( cout << "but if u directly output true&&false u get "<< true )&&false;
+ 2
&& checks if both sides are true, but here, just one side is true. So it returns false.
+ 2
Coder Always these words are confusing. there are 2 ops to compare: && and "and". this is made cause different priorities in the op hirarchy. I think the prob here is the handling of the stream. To get it clear there would be brackets a plus.
+ 1
and operator is used for comparing two sides and if either one results false the output is false
+ 1
correct as all of you mentioned guys.
problem is using expressions in COUT in general.
in this cases with COUT I recommend you always to use variables, as you did in first two examples. It will be more clear to read and to find possible mistakes.
b = true && false
COUT << b
+ 1
b is a throw-away variable and causes confusion as it's another layer of indirection. Just do
std::cout << (true && false);
+ 1
std::cout << std::boolalpha;
Now you don't get 0 or 1 but true or false.
0
0&&1 results 0 only as one side is false and the other is true