C# Programming - Control Instructions - Discussion
Discussion Forum : Control Instructions - General Questions (Q.No. 16)
16.
Which of the following is another way to rewrite the code snippet given below?
int a = 1, b = 2, c = 0;
if (a < b) c = a;
Discussion:
6 comments Page 1 of 1.
Sparwhawk said:
4 years ago
B is incorrect because ternary operation cannot be written as a statement. In the case of answer A, the ternary operation is assigned to a variable C.
Afsha said:
5 years ago
I am confused with option A and B. Which one is right and why? Please explain.
Madusha said:
6 years ago
But is there anything wrong with the ternary operator in the option B?
Snehal said:
9 years ago
Why not option B?
Wiinai said:
10 years ago
Condition operator used in this code.
a<b condition true then it return 'a' value.
If condition false then it return 0;
Then that return value equals to C.
C = (a<b) ? a:0;
(or) If (a<b)c = a;
a<b condition true then it return 'a' value.
If condition false then it return 0;
Then that return value equals to C.
C = (a<b) ? a:0;
(or) If (a<b)c = a;
Warunika Senadheera said:
1 decade ago
Can anyone explain the answer?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers