Skip to content
Justice Tech School

Data Types and sizeof

sizeof gives the size of a type in bytes. Typical sizes are char 1, int 4, float 4 and double 8, but they depend on the system. Use unsigned for values that are never negative, and long or long long for bigger numbers. Integer division drops the decimals.

Example
printf("%zu %zu %zu\n", sizeof(char), sizeof(int), sizeof(double));
printf("%d\n", 7 / 2);
printf("%.1f\n", 7 / 2.0);
unsigned int u = 4000000000u;
printf("%u\n", u);

Result

1 4 8
3
3.5
4000000000

Exercise

Find the size of a type in bytes.

printf("%zu", (int));

Quiz Test

What is 7 / 2 with two ints?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.