C Language



Admission Enquiry Form

  

Ternary Operator in C




What is Ternary Operator in C Programming?

Ternary operator is that operator which works on three operands and it can replace certain types of if-then-else statements.Here, the first argument is some conditional or comparison argument, the second argument is the result if the condition is true,and the third is the result also but if condition is false.This operator is the (?:).This operator is also called as Conditional Operator.




First Example of Ternary operator:

Output

Value of c is 10

In the above code value of a is 10 and value of b is 20.Here,compiler first check the condition,and condition is ( a<b )which is true so control go to first expression that is a and then return the value of a and assign to c.So, the value of c will be 10.



Another Example of Ternary operator:


Output

False