Sizeof Operator in C

Level 271 keystrokes

Uses sizeof to print the size in bytes of int (usually 4) and char (always 1).

C code

// sizeof gives a type's size in bytes; int is usually 4
// %zu is the format specifier for size_t, the type sizeof returns
1printf("int: %zu\n", sizeof(int));
// char is 1 byte by definition, so this always prints "char: 1"
2printf("char: %zu\n", sizeof(char));

Output

int: 4
char: 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
  • (× 4
  • )× 4
  • ,× 2
  • ;× 2
  • :× 2
  • \× 2
  • %× 2

More C examples at level 2

← C typing practice