Sizeof Operator in C

Level 2112 keystrokes

Uses sizeof to print how many bytes int, char and double take; on typical systems this prints 4, 1 and 8.

C code

// sizeof(int) gives the size of int in bytes, usually 4
// %zu is the format specifier for size_t, the type sizeof returns
1printf("int: %zu\n", sizeof(int));
// sizeof(char) is 1 by definition in C, so this always prints "char: 1"
2printf("char: %zu\n", sizeof(char));
// A double (double-precision floating point) usually takes 8 bytes
3printf("double: %zu\n", sizeof(double));

Output

int: 4
char: 1
double: 8
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.

  • "× 6
  • (× 6
  • )× 6
  • ,× 3
  • ;× 3
  • :× 3
  • \× 3
  • %× 3

More C examples at level 2

← C typing practice