+ 9

Ternary operator

Why the condition evaluated to true ? https://code.sololearn.com/cdR8rHWvw897/?ref=app

20th Jul 2020, 10:49 PM
Ahmed Mahmoud
Ahmed Mahmoud - avatar
8 Antworten
+ 5
It might be useful to use the equality operator with the ternary operator int c = b/a>=3 ? a:b; result here is false, as 20/2 is 2 which means that the result is not greater or equal to 3
20th Jul 2020, 11:16 PM
D_Stark
D_Stark - avatar
+ 5
yes yes you are right thanks
20th Jul 2020, 11:08 PM
Ahmed Mahmoud
Ahmed Mahmoud - avatar
+ 5
i think there is no need for that in this situation it was a question in one of challenges in Sololearn
20th Jul 2020, 11:25 PM
Ahmed Mahmoud
Ahmed Mahmoud - avatar
+ 4
20/10 is 2 and any number greater than 0 evalutes to True ,hence a is the answer
20th Jul 2020, 10:52 PM
Abhay
Abhay - avatar
+ 3
no worries, I would say Abhay answer is best as this is the reason it's true 👍
20th Jul 2020, 11:27 PM
D_Stark
D_Stark - avatar
+ 2
Abhay not Only greater than 0 is true but any non zero value evaluates true ... so that number less than zero also evaluates true..!
21st Jul 2020, 4:06 AM
Shrinivas Gadade
Shrinivas Gadade - avatar
0
please how can I be a good programmer?
5th Jan 2021, 9:46 AM
Mustafa Jafar
Mustafa Jafar - avatar
0
Mustafa Jafar first learn concept clearly and then do practice . "practice makes man perfect" so, keep practicing and practice will develop your logical thinking 👍
5th Jan 2021, 11:06 AM
Shrinivas Gadade
Shrinivas Gadade - avatar