Ternary operator | Sololearn: Learn to code for FREE!


Ternary operator

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

7/20/2020 10:49:47 PM

Ahmed Mahmoud

8 Answers

New Answer


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


yes yes you are right thanks


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


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


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


Abhay not Only greater than 0 is true but any non zero value evaluates true ... so that number less than zero also evaluates true..!


please how can I be a good programmer?


Mustafa Jafar first learn concept clearly and then do practice . "practice makes man perfect" so, keep practicing and practice will develop your logical thinking 👍