as given in the example, no%2 will give a number (0 or 1) so how does that mean that when no%2=0 it is a true statement and the first statement is executed ?
True and false in ternary operator
HI @ebanigupta121, the ternary operator follows the following syntax:
() ; Statement 1 : Statement 2 ;
Now for a given no. n n%2 can either result in 1(if n is odd) or in 0( if n is even).
Our given condition is
( n%2==0 ) ? … : … ;
So if n is even then result of condition will be (0==0) which is True and hence Statement 1 will be executed else the number n will be odd and condition will be 1==0 which is False and hence Statement 2 will be executed.
Hope you got this
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.