+ 1

what are ternary operators?

25th Jul 2016, 3:13 PM
Apoorva MITTAL
Apoorva MITTAL - avatar
4 Respostas
+ 4
ternary operators are conditional statements. Example: int a=2;b=3; int c=a>b?10:20; Since, value of a is smaller than b, so c will get 20. If a was greater than b, then c would get 10. Syntax: <condition>?<true value>:<false value>;
25th Jul 2016, 4:03 PM
Aditya Agarwal
Aditya Agarwal - avatar
+ 3
unary - single binary - two ternary - three So ternary operator is an operator which has three operands. The character pair ? : is a ternary operator. operand1 ? operand2 : operand3 Here operand1 should be an expression/decision statement, operand 2,3 can be expressions or constants. It is similar to this if else statement if(operand1) variable = operand2; else variable = operand3;
12th Feb 2017, 11:37 AM
Kommoju Sunil Kumar
Kommoju Sunil Kumar - avatar
+ 1
A ternary operator has 3 operands. There is only one ternary operator ie Conditional operator.
26th Jul 2016, 8:29 AM
Programmer
+ 1
This operator is like if condition, if term before ? is true then first condition executed otherwise second. e.g. int a=2,b=3; b>a?yes:no Ans is "yes".
28th Mar 2017, 5:21 AM
Surya Pratap Singh
Surya Pratap Singh - avatar