Do Conditional Operators have precedence? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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?

7th Feb 2018, 9:24 AM
D_Stark
D_Stark - avatar
11 Respostas
+ 23
yes /*i submitted a good quiz on that but was declined saying "so many quizzes of this type already exist" šŸ˜‚*/
7th Feb 2018, 10:15 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 23
yaa we have that type of quiz in C++ guess what I just played ...šŸ˜‚šŸ˜‚šŸ˜‚ cout<<!(1||0&&!1) //output :- 0
7th Feb 2018, 10:30 AM
šŸŒ›DTšŸŒœ
šŸŒ›DTšŸŒœ - avatar
+ 19
true||false&&false //answer will be true , but most ppl do it as false šŸ˜… //so i made this as quiz
7th Feb 2018, 10:24 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 17
it will be treated as true||(false&&false) ..... true||false ... ie true //bcz precedence of && is greater than that of || @David
7th Feb 2018, 10:43 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 10
@Cool Coding Thank you very much! i do wonder though why i have only just learned this now. šŸ¤”
7th Feb 2018, 9:51 AM
D_Stark
D_Stark - avatar
+ 10
@ Gaurav did you make code quiz about it? if so can i have a look at it ? šŸ˜€
7th Feb 2018, 10:22 AM
D_Stark
D_Stark - avatar
+ 8
Thank you very much Gaurav thats perfect šŸ‘šŸ‘šŸ‘šŸ‘
7th Feb 2018, 10:49 AM
D_Stark
D_Stark - avatar
+ 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
7th Feb 2018, 10:36 AM
D_Stark
D_Stark - avatar
+ 7
šŸ¤” now im unsure what answer is right is there anyway to see step by step execution of this exspression? thanks
8th Feb 2018, 11:47 PM
D_Stark
D_Stark - avatar
+ 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.
8th Feb 2018, 10:50 AM
Nashat
Nashat - avatar