C data types explained

Every variable in C needs a declared type, because the compiler needs to know exactly how much memory to reserve for it and how to interpret the bits stored there. Here's what each core type actually means in practice.

The basic types

TypeTypical sizeUsed for
char1 byteA single character or small integer (-128 to 127)
int4 bytesWhole numbers, the most commonly used numeric type
float4 bytesDecimal numbers, ~6-7 digits of precision
double8 bytesDecimal numbers needing more precision than float
void—Represents "no type" — used for functions that return nothing

Note: exact sizes can vary slightly by compiler and platform. You can always check the real size on your system with the sizeof() operator, shown below.

Modifiers: short, long, signed, unsigned

C lets you fine-tune the basic types with modifiers:

Checking sizes yourself

Rather than memorizing sizes, you can check them directly using sizeof() — paste this into the C compiler and run it:

#include <stdio.h>

int main() {
    printf("char: %zu byte\n", sizeof(char));
    printf("int: %zu bytes\n", sizeof(int));
    printf("float: %zu bytes\n", sizeof(float));
    printf("double: %zu bytes\n", sizeof(double));
    printf("long: %zu bytes\n", sizeof(long));
    return 0;
}

Choosing the right type

A common mistake: mismatched format specifiers

One of the most frequent beginner errors is pairing the wrong printf/scanf format specifier with a variable's actual type — for example, using %d with a float. This compiles with a warning but produces garbage output. See our guide on common C compiler errors for the correct specifier to use with each type.

← Try this in the C compiler