?: is known as conditional operator or ternary operator.
syntax:
(condition)?<statement followed="" if="" condition="" is="" true="">:< statement followed if condition is false>
If expression is Boolean that means it results either true or false then this type of operator is used. If expression(condition) is true then it follows first statement else it follows second one.
Program:
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,z;
printf(“Enter value of a:”);
scanf(“%d”,&a);
printf(“Enter value of b:”);
scanf(“%d”,&b);
printf(“Enter value of c:”);
scanf(“%d”,&c);
z=(a>b)?((a>c)?a:c):((b>c)?b:c);
printf(“Greatest of 3 numbers is %d”,z)
getch();
}
Output:
Enter value of a: 23
Enter value of b: 45
Enter value of c: 33
Greatest of 3 numbers is 45