+ 5

# What is ternary operator?

:)

10th Aug 2017, 5:41 PM
+ 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. ~
+ 5
thx
10th Aug 2017, 5:55 PM
+ 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 🇸🇬
+ 4
13th Aug 2017, 10:43 AM
👑 Prometheus 🇸🇬
+ 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
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
- 4