0
Ternary operator
could anyone tell me what a ternary oporator is, thank you
2 Réponses
+ 1
A ternary operator is a type of operator which needs 3 operands to Operate . Like Unary operator which trigger computation on one operand and like Binary operator which needs 2 operands to Operate .. Ternary operator needs 3 operands to Operate.
Ex - ?: -> conditional operator
operand1 ? operand2 : operand3
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;