Logical Operators in C

Level 257 keystrokes

Applies logical AND (&&), OR (||) and NOT (!) to a = 1 (true) and b = 0 (false) and prints the results "0 1 1".

C code

// Plain ints serve as truth values: any nonzero value is true and 0 is false
1int a = 1, b = 0;
// a && b is 0 (b is false), a || b is 1 (a is true), !b is 1, so "0 1 1"
2printf("%d %d %d", a && b, a || b, !b);

Output

0 1 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
  • %× 3
  • ;× 2
  • "× 2
  • &× 2
  • =× 2
  • |× 2
  • !× 1
  • (× 1
  • )× 1

More C examples at level 2

← C typing practice