C

Conditional Operator

It is also known as ternary operator and used to evaluate conditional expression.

Syntax:

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.

Example:

// 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();
}

Output:

Command Prompt
Enter Two Number
50
30
50 is Max Number



Subscribe us on Youtube

Share This Page on

Question


pratik | 18-Apr-2016 05:23:06 pm

Its to helpful for learning c programming


Ask Question