+ 5
What is ternary operator?
:)
7 Answers
+ 24
condition?caseTrue:caseFalse (b=a==1?5:3)
just a shortcut of if-else used in assignments...
+ 5
thx
+ 5
Ternary->3
Some operators deal with 2 parameters (they're binary operators)
Ternary olerators deal with 3 parameters.
Valwntin gave an example of ternary.
Binary operatpr is easy.
+,-,*,/,//,etc. are all your binary operators
+ 4
kaushal you got your badge now go away he is asking a good question.
+ 2
Ternary operator can be use instead of if else, nested if and if else ladder. You can replace multiple lines of if else code with single line of code using Ternary operator.
variable = (condition) ? value for true : value for false;
For eg.
Code using if else
If(condition) {
res=1;
}
else {
res=0
}
Same code using Ternary operator
res = (condition) ? 1 : 0;
0
Basically, it is like a simple if-else situation, abbreviated.
int x;
if(2>1)
x = 5;
else
x = 3;
This translates to:
int x;
x = 2>1? 5: 3;
- 4
you are asking wrong question