What is the output of the following statements?
int b=15, c=5, d=8, e=8, a;
a = b>c ? c>d ? 12 : d>e ? 13 : 14 : 15;
printf("%d", a);
int b=15, c=5, d=8, e=8, a;
a = b>c ? c>d ? 12 : d>e ? 13 : 14 : 15;
printf("%d", a);
A. 13
B. 14
C. 15
D. 12
E. Garbage Value
Answer: Option B
Solution(By Examveda Team)
Expressiona = b>c ? c>d ? 12 : d>e ? 13 : 14 : 15;
can be rewritten as
if(b>c)
{
if(c>d)
a = 12;
else
{
if(d>e)
a = 13;
else
a = 14;
}
}
else
{
a = 15;
}
Join The Discussion
Comments ( 2 )
Related Questions on Operators and Expressions
What does the ++ operator do in C when applied to a variable?
A. Decrements by 1
B. Adds 1
C. Doubles the value
D. Leaves it unchanged
Superb
best