Você está na página 1de 7

Ternary operators in c

By : Vijay Kumar Roll : 254

Operators can be
binary
unary ternary

involving 2 operands
involving 1 operand involving 3 operands

2+3
-3 follows

Ternary Operator

a Ternary operator is an operator that takes three arguments. The arguments and result can be of different types. Since this operator is often the only existing ternary operator in the language, it is referred as "the ternary operator", though it is more accurately referred to as the conditional operator.

Introduction To Ternary Operator


C

ternary operator is also referred as conditional operator because: It is only operator that has three operands. It is a shorthand of combination of the if-else and return statement.

Conditional (Ternary) Operator ? :


SYNTAX
Expression1 ? Expression2 : Expression3

MEANING If Expression1 is true, then the value of the entire expression is Expression2. Otherwise, the value of the entire expression is Expression 3.

FOR EXAMPLE . . .

Using Ternary Operators


// Finds the smaller of two float values double double double min ; x; y;

min = ( x < y ) ? x : y ;

Você também pode gostar