C Workshop · Data Types and sizeof
Lesson C

Data Types and sizeof

sizeof tells you how many bytes a type uses on this compiler and machine.

What it is

sizeof asks the compiler a simple question: how many bytes does this type use on this machine? It is not a guess and not a constant baked into the C language for int — it is a fact about this compiler and CPU.

Approach

  1. Call sizeof(int).
  2. Print it. On many Kodin setups this is 4, which matches the sample.
  3. Remember: char is at least 1 byte; float and double are different widths.

Where this is used in the real world

Diagram

1 Bchar
4 Bint (typical)
4 Bfloat
8 Bdouble

Run algorithm

Each step highlights the matching C line. Program output appears only when a line that prints actually runs.

Ready
C code
1#include <stdio.h>
2int main(void) {
3  printf("%zu\n", sizeof(int));
4  return 0;
5}
What this line does
Press Run algorithm. The highlight will move through the C code.
Program output
(no output yet)

Check your understanding

Five questions. Pick one answer each, then Check answers. The correct choice turns green.

1. sizeof(int) measures:

Size in bytes, implementation-defined.

2. On many desktop compilers sizeof(int) is:

Often 4, not guaranteed by the language.

3. Which type is at least 1 byte?

char is the unit of sizeof.

4. %zu is commonly used to print:

size_t matches sizeof.

5. float vs double:

double is usually 8 bytes.