Pre-Decrement Operator in C

Level 251 keystrokes

Shows pre-decrement: --x lowers x from 10 to 9 before its value is used, so both printf calls print 9.

C code

// x starts at 10
1int x = 10;
// Pre-decrement: --x lowers x to 9 first, then passes 9 to printf
2printf("%d\n", --x);
// Prints 9 again, confirming x itself was changed (x-- would have printed 10 first)
3printf("%d\n", x);

Output

9
9
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
  • %× 2
  • =× 1

More C examples at level 2

← C typing practice