Thursday, October 27, 2011

Conditional operator (if operator)

conditional operator (also called "if operator"), if in the form of

(condition ? statements if condition is true : statements if condition is false)

It's equal to:
if(condition){
statements if condition is true;
}else{
statements if condition is false;
}

#include <iostream>

using namespace std;

int main()
{
cout << "conditional operator (if operator)" << endl << endl;

cout << (true ? "It's TRUE" : "It's FALSE") << endl;
cout << (false ? "It's TRUE" : "It's FALSE") << endl;

cout << "3 > 5: " << ((3 > 5) ? "Yes" : "No") << endl;
cout << "'Z' > 'X': " << (('Z' > 'X') ? "Yes" : "No") << endl;

return 0;
}


Conditional operator (if operator)



No comments:

Post a Comment