Conditional Operator in C++
Notes:
Conditional Operator in C++ Programming Language:
Conditional Operator ( ?: ):
- is the 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 <iostream>
using namespace std;
int main()
{
int num = 15;
cout << num << " is " << ((num%2==0) ? "even" : "odd") << endl;
return 0;
}