Ternary operator | SoloLearn: Learn to code for FREE!

+9

Ternary operator

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

7/20/2020 10:49:47 PM

Ahmed Mahmoud

6 Answers

New Answer

+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

+5

yes yes you are right thanks

+5

i think there is no need for that in this situation it was a question in one of challenges in Sololearn

+4

20/10 is 2 and any number greater than 0 evalutes to True ,hence a is the answer

+3

no worries, I would say Abhay answer is best as this is the reason it's true 👍

+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..!