Data Types in C
A data type specifies: what kind of data a variable will store, how many bytes of memory to allocate, and what operations are allowed.
Primary Data Types with sizeof()
c
#include <stdio.h>
int main() {
// ── Basic types ──────────────────────────────
char c = 'A'; // character
short s = 32000; // small integer
int i = 2147483647; // regular integer
long l = 1000000000L; // large integer
long long ll = 9000000000LL; // very large
float f = 3.14f; // 7-digit decimal
double d = 3.14159265358; // 15-digit decimal
// ── Print types and sizes ────────────────────
printf("Type Size Value\n");
printf("-------------------------------------------\n");
printf("char : %lu byte | %c\n", sizeof(c), c);
printf("short : %lu bytes | %d\n", sizeof(s), s);
printf("int : %lu bytes | %d\n", sizeof(i), i);
printf("long : %lu bytes | %ld\n", sizeof(l), l);
printf("long long : %lu bytes | %lld\n",sizeof(ll), ll);
printf("float : %lu bytes | %.2f\n",sizeof(f), f);
printf("double : %lu bytes | %lf\n", sizeof(d), d);
return 0;
}▶ Output
Type Size Value ------------------------------------------- char : 1 byte | A short : 2 bytes | 32000 int : 4 bytes | 2147483647 long : 8 bytes | 1000000000 long long : 8 bytes | 9000000000 float : 4 bytes | 3.14 double : 8 bytes | 3.141593
Complete Data Type Reference Table
| Type | Bytes | Range | Format Specifier | Best Used For |
|---|---|---|---|---|
| char | 1 | -128 to 127 | %c | Single characters, ASCII codes |
| unsigned char | 1 | 0 to 255 | %c / %hhu | Byte values, small positive numbers |
| short | 2 | -32,768 to 32,767 | %hd | Small integers |
| int | 4 | -2.1B to 2.1B | %d | Regular whole numbers (age, count, marks) |
| unsigned int | 4 | 0 to 4.2B | %u | Positive-only numbers (size, count) |
| long | 8 | Very large | %ld | Large whole numbers |
| float | 4 | 7-digit precision | %f | Prices, temperatures, weights |
| double | 8 | 15-digit precision | %lf | Scientific, financial calculations |
| long double | 16 | 18-digit precision | %Lf | Extreme precision required |
📌 Note:
sizeof() returns the size in bytes on YOUR specific machine. Sizes can differ between 32-bit and 64-bit systems.