Sizeof Operator in C

Level 4200 keystrokes

Uses sizeof to determine the size in bytes of different data types and structures.

C code

// Define a structure with different types
1struct Data {
2 char c;
3 int i;
4 double d;
5};
// sizeof gives the size in bytes; sizeof(char) is always 1
6printf("char: %lu\n", sizeof(char));
// int is typically 4 bytes
7printf("int: %lu\n", sizeof(int));
// double is typically 8 bytes
8printf("double: %lu\n", sizeof(double));
// Includes padding: c(1) + 3 padding + i(4) + d(8) = 16 on common systems
9printf("struct: %lu\n", sizeof(struct Data));

Output

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

  • ;× 8
  • "× 8
  • (× 8
  • )× 8
  • ,× 4
  • :× 4
  • \× 4
  • %× 4
  • {× 1
  • }× 1

More C examples at level 4

← C typing practice