It is also known as ternary operator and used to evaluate conditional expression.
variable = epr1 ? expr2 : expr3
This Syntax can be Read as, If epr1 Condition is true ?
Then value of expr2 is assign :
Otherwise value of expr3 is assign to variable
.
// Write a C Program Which Find Max Number Using Conditional Operator.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,max;
clrscr();
printf("Enter Two Number\n");
scanf("%d %d",&a,&b);
max = a>b ? a : b; /*Conditional Operation*/
printf("%d is Max Number",max);
getch();
}
Ask Question