Ternary Operator
Ternary Operators are used on three operands or on
there variables. It is represented with ? : . It is also
called as conditional operator.
Advantage of Ternary Operator
 Using Ternary Operator reduce the number of line
codes and improve the performance of application.
 Syntax:
Expression-1 ? Expression-2 : Expressiion-3
 Example:
a>b ? printf(“a is less”); : printf(“b is less”);
Example of Ternary Operator
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c, large;
clrscr();
printf("Enter any three number: ");
scanf("%d%d%d",&a,&b,&c);
large=a>b ? (a>c?a:c) : (b>c?b:c);
printf("Largest Number is: %d",large);
getch();
}
Output:
Enter any three numbers: 10 30 20
Largest number is 30
Reference
http://www.tutorial4us.com/cprogramming/c-ternary-operator

Ternary operator

  • 2.
    Ternary Operator Ternary Operatorsare used on three operands or on there variables. It is represented with ? : . It is also called as conditional operator.
  • 4.
    Advantage of TernaryOperator  Using Ternary Operator reduce the number of line codes and improve the performance of application.  Syntax: Expression-1 ? Expression-2 : Expressiion-3  Example: a>b ? printf(“a is less”); : printf(“b is less”);
  • 6.
    Example of TernaryOperator #include<stdio.h> #include<conio.h> void main() { int a, b, c, large; clrscr(); printf("Enter any three number: "); scanf("%d%d%d",&a,&b,&c); large=a>b ? (a>c?a:c) : (b>c?b:c); printf("Largest Number is: %d",large); getch(); } Output: Enter any three numbers: 10 30 20 Largest number is 30
  • 7.