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.


condition ? expression1 : expression2

#include <iostream.h>
  void main()
     int  age;
     cout<< "enter your age" << endl;
     (age>=18) ? cout << "you can vote" <<endl : cout<< you cant vote<<endl;


enter your age 21
you can vote


The topic on C-programming - Conditional operator is posted by - Malar

Hope you have enjoyed, C-programming - Conditional operatorThanks for your time

Tech Bluff