+ 13
Do Conditional Operators have precedence?
i come across a question in submissions about these operator's != , || , && having precedence in java. i know that maths operators do but i have never heard of conditional operator's having them before? i choose false but apparently i was wrong?
13 Answers
+ 23
yes
/*i submitted a good quiz on that but was declined saying "so many quizzes of this type already exist" 😂*/
+ 23
yaa we have that type of quiz in C++
guess what I just played ...😂😂😂
cout<<!(1||0&&!1)
//output :- 0
+ 19
true||false&&false
//answer will be true , but most ppl do it as false 😅
//so i made this as quiz
+ 17
it will be treated as true||(false&&false) ..... true||false ... ie true
//bcz precedence of && is greater than that of ||
@David
+ 10
@Cool Coding Thank you very much! i do wonder though why i have only just learned this now. 🤔
+ 10
@ Gaurav did you make code quiz about it? if so can i have a look at it ? 😀
+ 8
Thank you very much Gaurav thats perfect 👍👍👍👍
+ 7
@ Gaurav can you explain to me how i should read true||false&&false i have never seen this before whats going on with me haha 😨 thanks
+ 7
🤔 now im unsure what answer is right is there anyway to see step by step execution of this exspression? thanks
+ 2
true||false&&false..... The answer is false.
The checking starts from left to right and not according to precedence.
While checking from left to right the execution takes place in this way.... 👇
(true||false)&&false
true&&false
false
I took help of parentheses just to explain you... Thank you.