As a part of #100 day coding challenge on C programming/Embedded C posting questions in below link.
http://forum.talenteve.com/viewforum.php?f=46
Question on Day#1 as a part of this is below.
The question is based on conditional operator or ternary operator.
---------------------------------------
The conditional operator can be written as,
Variable = Expression ? Value 1 : Value 2
If Expression is evaluated as True, Variable = Value 1
If Expression is evaluated as False, Variable = Value 2
---------------------------------------
The conditional operator can also be written as,
Expression ? Expression 1 : Expression 2
If Expression is evaluated as True, Expression 1 is evaluated
If Expression is evaluated as False, Expression 2 is evaluated
---------------------------------------
i is initialized as 10.
Considering, above declaration of conditional statements,
From the conditional operator in main function (2nd statement in main), it checks for (i>=5) and as it is true, the first option (j=10) is chosen.
So, the print statement prints 10,10 as the variables i,j are printed.
0 Comments