Computer Science
What will be the output when the following statements are executed?
int v,s,n=550;
s = n + v > 1750? 400:200;
When,
(a) v = 500
(b) v = 1500
Answer
(a) v = 500
200
Working
n + v = 500 + 550 = 1050. As 1050 is less than 1750 so condition of ternary operator is false. Ternary operator returns 200 as its output that gets assigned to s.
(b) v = 1500
400
Working
n + v = 1500 + 550 = 2000. As 2000 is greater than 1750 so condition of ternary operator is true. Ternary operator returns 400 as its output that gets assigned to s.