Boolean Expression in C++

Level 299 keystrokes

Stores the results of two comparisons in bool variables and combines them with &&; both are true, so 1 is printed.

C++ code

// Initializes x with 5
1int x = 5;
// A comparison produces a bool: 5 > 0 is true
2bool isPositive = x > 0;
// 5 < 10 is also true
3bool isSmall = x < 10;
// true && true is true, which cout prints as 1
4cout << (isPositive && isSmall) << endl;

Output

1
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.

  • <× 5
  • ;× 4
  • =× 3
  • &× 2
  • (× 1
  • )× 1
  • >× 1

More C++ examples at level 2

← C++ typing practice