Conditional Operator
Conditional Operator
Conditional operator is a simple dicision making structure.It evaluates a condition and returns one of two values based on the result
of the condition.It can be used in place of simple if-else structure.It is also called Ternary operator as it uses three operands.
Syntax
Example
N=(a>50)?1:0;
The above statement will assign the value 1 to the variable N if the condition a>50 is true. It will assign the value 0 to N if the
condition is false.
If(a>50)
N=1;
else
N=0;
Program
#include<stdio.h>
#include<conio.h>
main()
int n;
scanf(“%d”,&n);
(n%7==0)?printf(“divisible”):printf(“not divisible”);
getch();