+ 5

What is ternary operator?

:)

10th Aug 2017, 5:41 PM
Adhiraj Dhar
Adhiraj Dhar - avatar
7 Answers
+ 24
condition?caseTrue:caseFalse (b=a==1?5:3) just a shortcut of if-else used in assignments...
10th Aug 2017, 5:53 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 5
thx
10th Aug 2017, 5:55 PM
Adhiraj Dhar
Adhiraj Dhar - avatar
+ 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
12th Aug 2017, 1:05 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 4
kaushal you got your badge now go away he is asking a good question.
13th Aug 2017, 10:43 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 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;
19th Aug 2017, 9:09 PM
Shishir Navale
Shishir Navale - avatar
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;
11th Sep 2019, 5:37 AM
A Darren Cruz
A Darren Cruz - avatar
- 4
you are asking wrong question
13th Aug 2017, 10:40 AM
kaushal kumar singh
kaushal kumar singh - avatar