(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;
}
No comments:
Post a Comment