Logical Not Operator in C++

Level 265 keystrokes

Inverts the bool active (false) with the ! operator; !active is true, so Inactive is printed.

C++ code

// Declares the bool active and sets it to false
1bool active = false;
// ! (logical NOT) turns false into true and true into false
// !active is true here, so the block runs
2if (!active) {
// Prints Inactive
3 cout << "Inactive" << endl;
4}

Output

Inactive
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this C++ code and how often they appear.

  • <× 4
  • ;× 2
  • "× 2
  • !× 1
  • (× 1
  • )× 1
  • {× 1
  • }× 1
  • =× 1

More C++ examples at level 2

← C++ typing practice