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
| Type | Typical size | Used for |
|---|---|---|
char | 1 byte | A single character or small integer (-128 to 127) |
int | 4 bytes | Whole numbers, the most commonly used numeric type |
float | 4 bytes | Decimal numbers, ~6-7 digits of precision |
double | 8 bytes | Decimal 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:
- short int — usually 2 bytes, a smaller range than a normal int.
- long int — usually 4 or 8 bytes, a larger range than a normal int.
- long long int — at least 8 bytes, for very large whole numbers.
- unsigned — removes the sign, so the full range is used for positive numbers only (e.g.
unsigned intstores 0 to ~4.29 billion instead of roughly ±2.1 billion).
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
- Use
intby default for whole numbers unless you have a specific reason not to. - Use
floatfor decimal values where a small precision loss is acceptable (e.g. simple measurements). - Use
doublefor anything requiring more precision — most scientific or financial-style calculations. - Use
charfor single characters, or as a small integer when memory is tight (e.g. embedded systems). - Use
unsignedonly when a value can never logically be negative (e.g. array sizes, counters).
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.