Logical And in C++

Level 299 keystrokes

Combines two conditions with && (age at least 18 and having a license); both are true, so Can drive is printed.

C++ code

// Stores the age 25 in age
1int age = 25;
// A bool holds only true or false; here the person has a license
2bool hasLicense = true;
// && (logical AND) is true only when both sides are true
// 25 >= 18 is true and hasLicense is true, so the block runs
3if (age >= 18 && hasLicense) {
// Prints Can drive
4 cout << "Can drive" << endl;
5}

Output

Can drive
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
  • ;× 3
  • =× 3
  • "× 2
  • &× 2
  • (× 1
  • )× 1
  • {× 1
  • }× 1
  • >× 1

More C++ examples at level 2

← C++ typing practice