+ 2

Which has higher priority over && and || operator?

like what will be the output of 0 && 1 || 1 it may be either 0 if started from || operator or may be 1 if started from && operator.

15th Jan 2017, 6:59 AM
Rishabh Agrawal
Rishabh Agrawal - avatar
9 ответов
+ 8
I've tested with Code Playground and I have obtained 1. You might have to check your code syntax.
15th Jan 2017, 7:24 AM
Hatsy Rei
Hatsy Rei - avatar
+ 7
Tsk, your code outputs zero because cout prints what comes next directly, like return. To clear up the confusion, place brackets to your entire statement after cout. cout<<(0 && 1 ||1);
15th Jan 2017, 8:09 AM
Hatsy Rei
Hatsy Rei - avatar
+ 6
0 && 1 || 1 should end up being 1.
15th Jan 2017, 7:17 AM
Nina
Nina - avatar
+ 6
I agree with Hasty. Can we see your code?
15th Jan 2017, 7:25 AM
Nina
Nina - avatar
+ 2
Thanks @hatsy rei. It was my silly mistake.
15th Jan 2017, 8:19 AM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 1
You could check my code "operator". Plz it's giving 0 as output.
15th Jan 2017, 8:07 AM
Rishabh Agrawal
Rishabh Agrawal - avatar
0
@Nina But when I tried it in code playground it results in 0.
15th Jan 2017, 7:20 AM
Rishabh Agrawal
Rishabh Agrawal - avatar
0
@hatsy It also says && has higher priority over || so answer would be 1 but it gives 0.
15th Jan 2017, 7:21 AM
Rishabh Agrawal
Rishabh Agrawal - avatar