The program demonstrates the use of the ternary operator (also known as the conditional operator). The ternary operator is a shorthand way of writing an if-else statement. The syntax for the ternary operator is as follows:
Syntax:
condition ? value1 : value2 ;
This can be read as "if condition is true, return value1, otherwise return value2."
In the program, the ternary operator is used to determine the greater of two numbers, a and b. The condition being checked is a > b. If this condition is true, the greater of the two numbers is a, and so a is returned. If the condition is false, the greater of the two numbers is b, and so b is returned. The returned value is then stored in variable c and printed out to the console. :
// Conditional Operator Statement ?: #include<stdio.h> int main() { int a,b,c; printf("\nEnter The Value of A & B : \n"); scanf("%d%d",&a,&b); c=a>b?a:b; printf("\nThe Greatest No is %d",c); return 0; }To download raw file Click Here
Enter The Value of A & B : 23 45 The Greatest No is 45
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions