What are the basic data types in C and their typical sizes?
The C standard defines integer types by minimum numeric range, not by byte size. A byte (sizeof(char) == 1) is at least 8 bits (CHAR_BIT >= 8), but some platforms (notably DSP chips) use 16-bit or 32-bit bytes, which shifts all sizeof values.
1. char -- stores a single character or small integer.
- Minimum range: -127 to 127 (signed) or 0 to 255 (unsigned). Whether plain
charis signed or unsigned is implementation-defined. sizeof(char)is always 1, but 1 byte is not always 8 bits.
2. int -- general-purpose integer.
- Minimum range: -32,767 to 32,767 (the standard requires at least 16 bits of value).
- On most modern 32/64-bit desktops it holds -2,147,483,648 to 2,147,483,647 (32-bit), but that is not guaranteed.
- Modifiers:
short(>= 16-bit range),long(>= 32-bit range),long long(>= 64-bit range).
3. float -- single-precision floating point.
- Typically IEEE 754 binary32 (4 bytes on most platforms).
- Precision: ~6-7 significant decimal digits.
4. double -- double-precision floating point.
- Typically IEEE 754 binary64 (8 bytes on most platforms).
- Precision: ~15-16 significant decimal digits.
5. void -- represents the absence of type.
- Used for functions that return nothing, generic pointers (
void *), and to indicate no parametersf(void).
The standard guarantees these minimum ranges (C11 5.2.4.2.1) and this ordering:
sizeof(char)== 1 (always, by definition)sizeof(char)<=sizeof(short)<=sizeof(int)<=sizeof(long)<=sizeof(long long)- Use
<limits.h>for the actual ranges andCHAR_BITfor bits per byte on your platform.
1. char: sizeof==1 (but 1 byte >= 8 bits, not always exactly 8)
2. int: minimum range -32767..32767, typically 32-bit on desktops
3. float: ~7 decimal digits precision (usually IEEE 754)
4. double: ~15 decimal digits precision (usually IEEE 754)
5. void: no value, used for function returns and generic pointers
6. Modifiers: short, long, long long, signed, unsigned
7. The standard defines types by minimum range, not byte count
#include <stdio.h>
#include <limits.h>
#include <float.h>
int main(void) {
printf("char: %zu byte(s), range: %d to %d\n",
sizeof(char), CHAR_MIN, CHAR_MAX);
printf("short: %zu byte(s), range: %d to %d\n",
sizeof(short), SHRT_MIN, SHRT_MAX);
printf("int: %zu byte(s), range: %d to %d\n",
sizeof(int), INT_MIN, INT_MAX);
printf("long: %zu byte(s), range: %ld to %ld\n",
sizeof(long), LONG_MIN, LONG_MAX);
printf("long long: %zu byte(s), range: %lld to %lld\n",
sizeof(long long), LLONG_MIN, LLONG_MAX);
printf("float: %zu byte(s), precision: %d digits\n",
sizeof(float), FLT_DIG);
printf("double: %zu byte(s), precision: %d digits\n",
sizeof(double), DBL_DIG);
return 0;
}
- •C defines integer types by minimum numeric range, not byte size
- •sizeof(char) is always 1, but a byte is at least 8 bits (CHAR_BIT >= 8), not always exactly 8
- •int must hold at least -32767 to 32767; it is typically 32-bit on desktops but not guaranteed
- •void is not a real type -- you cannot declare a void variable
- •Use <limits.h> and <float.h> to check actual ranges on your platform
- •The standard defines types by minimum range, not byte count -- some DSP chips have 16-bit or 32-bit char, shifting all sizeof values
- •int is NOT guaranteed to be 4 bytes -- on some platforms it is 2 bytes
- •Whether plain char is signed or unsigned is implementation-defined
- •sizeof returns size_t (unsigned), use %zu format specifier
- •long is 4 bytes on Windows 64-bit but 8 bytes on Linux 64-bit (LLP64 vs LP64)