Ternary Operator in C

Level 124 keystrokes

Uses the ternary operator to return 1 if 5 is greater than 3.

C code

// The ternary operator has the form condition ? value_if_true : value_if_false
// 5>3 is true, so the value before : (1) is chosen
1printf("%d\n", 5>3?1:0);

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.

  • "× 2
  • ,× 1
  • ;× 1
  • :× 1
  • ?× 1
  • (× 1
  • )× 1
  • \× 1
  • %× 1
  • >× 1

More C examples at level 1

← C typing practice