← C++ tutorial

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.

Example
#include <iostream>
using namespace std;

int main() {
    int score = 85;
    bool passed = score >= 50 && score <= 100;
    cout << "Passed: " << (passed ? "true" : "false") << endl;
    return 0;
}
Output
Passed: true
Ready to go further?

These free tutorials are a preview of what a Code Secure Academy cohort covers, project work and all.

Explore our tracks
Don't miss out

Ready to build something real?

Create a free account to enroll in a track, and get notified the moment a cohort opens.

Create free account