C++
Operators
Arithmetic (+ - * /), comparison
(== != > <), and logical
(&& || !) operators work as in most C-family
languages.
Example: a boolean expression and a ternary for output
#include <iostream>
using namespace std;
int main() {
int score = 85;
bool passed = score >= 50 && score <= 100;
cout << "Passed: " << (passed ? "true" : "false") << endl;
return 0;
}
Passed: true
C++ doesn't have a genuine boolean-to-string conversion built in the
way some languages do — printing passed directly would show
1 or 0, not the word "true" or "false" — so the
ternary (passed ? "true" : "false") is a common, idiomatic
way to print a readable label instead.
#include <iostream>
using namespace std;
int main() {
int score = 85;
bool passed = score >= 50 && score <= 100;
cout << "Passed: " << (passed ? "true" : "false") << endl;
return 0;
}
Passed: true