C has a handful of built-in arithmetic types whose sizes are implementation-defined — the standard only guarantees minimum ranges. Always measure with sizeof.
The basic types
| Type | Guaranteed minimum | Typical size (64-bit Linux/macOS) | Format |
|---|---|---|---|
char | 8 bits | 1 byte | %c / %d |
short | 16 bits | 2 bytes | %hd |
int | 16 bits | 4 bytes | %d |
long | 32 bits | 8 bytes (4 on 64-bit Windows) | %ld |
long long | 64 bits | 8 bytes | %lld |
float | ~6 decimal digits | 4 bytes (IEEE 754 single) | %f |
double | ~10 digits (15 in practice) | 8 bytes (IEEE 754 double) | %f / %lf |
long double | ≥ double | 16 bytes x86-64 Linux, 8 on Apple arm64 | %Lf |
_Bool / bool | holds 0 or 1 | 1 byte | %d |
void | no value | — | — |
Measure with sizeof
#include <stdio.h>
#include <stdbool.h>
int main(void) {
printf("char %zu\n", sizeof(char));
printf("short %zu\n", sizeof(short));
printf("int %zu\n", sizeof(int));
printf("long %zu\n", sizeof(long));
printf("long long %zu\n", sizeof(long long));
printf("float %zu\n", sizeof(float));
printf("double %zu\n", sizeof(double));
printf("long double %zu\n", sizeof(long double));
printf("bool %zu\n", sizeof(bool));
printf("pointer %zu\n", sizeof(void *));
return 0;
}char 1
short 2
int 4
long 8
long long 8
float 4
double 8
long double 8
bool 1
pointer 8sizeof is an operator, not a function: it is evaluated at compile time (except for VLAs), and its result has type size_t — print it with %zu. Parentheses are only needed around a type: sizeof x works for a variable.
signed and unsigned
| Type | Range with 32-bit int |
|---|---|
int (= signed int) | −2 147 483 648 … 2 147 483 647 |
unsigned int | 0 … 4 294 967 295 |
signed char | −128 … 127 |
unsigned char | 0 … 255 (the type for raw bytes) |
plain char | either — signed on x86 and Apple arm64, unsigned on Linux ARM |
#include <stdio.h>
int main(void) {
unsigned int u = 0;
u = u - 1; /* unsigned arithmetic wraps modulo 2^32 — well defined */
printf("%u\n", u);
unsigned char byte = 250;
byte += 10; /* 260 mod 256 */
printf("%d\n", byte);
return 0;
}4294967295
4Floating point
#include <stdio.h>
int main(void) {
double a = 0.1 + 0.2;
printf("%.17f\n", a);
printf("%s\n", a == 0.3 ? "equal" : "not equal");
float f = 16777217.0f; /* 2^24 + 1 cannot be stored in a float */
printf("%.1f\n", f);
printf("%f %f\n", 7 / 2.0, (double)(7 / 2));
return 0;
}0.30000000000000004
not equal
16777216.0
3.500000 3.000000Characters are small integers
#include <stdio.h>
int main(void) {
char c = 'A';
printf("%c %d %c %d\n", c, c, c + 2, '0');
printf("digit value: %d\n", '7' - '0');
printf("sizeof 'A' = %zu\n", sizeof 'A'); /* a char literal has type int in C */
return 0;
}A 65 C 48
digit value: 7
sizeof 'A' = 4What is the size of int in C?
Is char signed or unsigned?
What does sizeof('A') return in C and in C++?