prev


Ternary Operator

26. Biggest of two numbers(6.7.2009)

/*
Program# 26
date : 25-12-2008
Biggest of two numbers
*/

#include <stdio.h>
main(){
int a,b,c;
printf("\nEnter two integers :");
scanf("%d %d",&a,&b);
c=(a>b)?a:b;
printf("\n%d : Biggest number\n",c);
}

output:
Enter two integers :23 34
34 : Biggest number

Things to note:
1. The syntax used in the statement c=(a>b)?a:b is expression 1? expression 2 : expression 3. It is called as ternary operators.? : are called as conditional operators.
2.First the expression 1 is evaluated, if it is true, the value of expression 2 is stored in c, if it is false, the expression 3 value is stored in the variable c.
next
blog comments powered by Disqus