# Ternary Operator in c - smartduniya

## Introduction to C Ternary Operator

C ternary operator is sometimes called conditional operator or trinary operator because it is a shorthand of combination of the if-else and return statement and has three operands. The syntax of C ternary operator is as follows:

#### `condition ? expression 1 : expression 2`

C first evaluates the condition. Based on the return value of the condition the second or third operand is evaluated:

• If the condition is evaluated to true (1), only the second operand (expresion 1) is evaluated. Then the operator return the value of the expression 1.
• If the condtion is evaluated to false (0), only the third operand (expression 2) is evaluated. The value of the expression 2 is returned.

The ternary operator can be rewritten as the if-else and return statement as follows:

## Example of C Ternary Operator

In this example, we are going to write an inline function that uses C ternary operator to find the minimum number between two integers.

#### Output :

```x=10,y=15
min(x,y)=10```