C# Programming - Operators - Discussion

Discussion Forum : Operators - General Questions (Q.No. 17)
17.
What will be the output of the C#.NET code snippet given below?
int a = 10, b = 20, c = 30; 
int res = a < b ? a < c ? c : a : b; 
Console.WriteLine(res);
10
20
30
Compile Error / Syntax Error
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
15 comments Page 2 of 2.

Norbert said:   1 decade ago
The Syntax of Conditional Operator is:
(Condition)?True:False

Q: a < b ? a < c ? c : a : b;
A:
First you just separate the conditions from the given statement:
a < b ? (a < c ? c : a) : b
In the Above step i just separated the condition,
Now (a < c ? c : a) In this condition the answer is 30
(i.e) is c
Now the statement changes into
a < b ? c : b
Just replace that Statement with above answer.
And Now that answer is C..

Thats it..
I hope you may got it.. Thank you..

Prakash said:   1 decade ago
I didnt get it:- (.

Some one please explain properly.

Bhavika said:   1 decade ago
Please explain more briefly.

Sarthak said:   1 decade ago
@divya:
((a<b)?(a<c?c:a):b))
first a<c ans is true so ans c=30....next a<b ?c:b ans is true again so c...n c=30.done..!!

Divya said:   1 decade ago
Can anyone explain how the answer came?


Post your comments here:

Your comments will be displayed after verification.