Conditional Operator in C Programming Language
Notes:
Conditional Operator in C Programming Language:
Conditional Operator ( ?: ):
- is the only ternary operator in C. It accepts 3 operands.
(operand1) ? operand2 : operand3;
Where:
operand1: must be a condition
operand2: value1 // true part
operand3: value2 // false part
Ex: Program to find the given number is even or odd
#include <stdio.h>
int main()
{
int num = 10;
printf("%d is %s\n", num, (num%2==0)? "even" : "odd");
return 0;
}