Conditional operators in c

Conditional operators in c-:  In c language provide a special type operators . This is called the ternary operators.  A ternary operators pair in “?” is available in c language its called a conditional operators for example  if we have 3  condition  we can use this operators

expression 1 ? expression 2 : expression 3

The operators “?” works as like here first  expression is evaluated if it is not =0, then expression 2 is evaluated and become the value of the expression. If expression 1 is false then expression 3 is evaluated and its value become the value is expression.

 c=(a>b) ? a:b;
in this example  if ... else statement is follow as like


Conditional operator example in c Programming

/* Conditional Operator in C Example */
# include<stdio.h>

 int main()
   int number;
 printf(" Enter your number here: \n ");
   scanf(" %d ", &number);
 (number >= 50) ? printf(" You are eligible  with travel  ") :
                printf(" You are not eligible  with travel ");
 return 0;

The out put of this program

Enter your number here:  62
You are eligible with travel

Enter Your number here: 44
You are not eligible  with travel  

Analysis of this example -: This conditional Operator in c program allows the user to enter his or her number and assign the user entered integer value to number in variable. If the user entered value is 50 or above, it will print the first statement after the ? symbol. If the user print the number of less then 50 its print the second statement.

More Read here about c programming operator

C support a rich set of built in operator we have already used several of them such as equal to add(+),Minus(-),  multiplication(*) and division(/). Operator are a symbol that tells the computer to perform certain mathematics or logical manipulation. operators are used in program to manipulate data and variables. they usually form a part of mathematical or logical expression.

Leave a Comment