Conditional Operators

Blog Contents

Conditional Operators:

Conditional operators also called ternary operators. Because it has three sets of expressions. Conditional operators return one value if the condition is true and returns another value if the condition is wrong.
The syntax of the expression and example is given below.




Let’s consider a program for the detailed understanding,
Int main()
Int a=10;
Int b=20;
Int c;
Printf(“The value after conditional operation is %d”,c=(a>b?a,b));
Return 0;


The value after conditional operation is 20
So in this program, We are initializing two integers a, b as 10 and 20 And another variable c. we are took
use of printf to print the output of conditional operator.
Conditional operator comparing the values of a and b. if a is greater than b. it will print the value of a or
b. In our example b is greater than a. so the conditional operators will print the variable b value.