C-programming - Conditional operator, C++ conditional operators
Conditional operator
The conditional operator evaluates an expression returning a value if that expression is true and a different one if the expression is evaluated as false. conditional operator is also called as ternary operator.syntax:
condition ? expression1 : expression2
#include <iostream.h> void main() { int age; cout<< "enter your age" << endl; cin>>age; (age>=18) ? cout << "you can vote" <<endl : cout<< you cant vote<<endl; }
output
enter your age 21 you can vote /pre>
The topic on C-programming - Conditional operator is posted by - Malar
Hope you have enjoyed, C-programming - Conditional operatorThanks for your time