Double Negation in C++

Level 123 keystrokes

Negates true twice with !! and prints the result, true, as 1.

C++ code

// !true is false, and negating that again with the second ! gives true
// !! is also a common idiom to turn any value into a bool; here cout prints 1
1cout << !!true << 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.

  • <× 4
  • !× 2
  • ;× 1

More C++ examples at level 1

← C++ typing practice