Lesson 05·C Programming
Data Types
Specifying memory requirements and representation ranges for variables
Data Types in C
When we declare a variable in a program, we must inform the compiler about the type of data it will store. This dictates the memory space allocated and the operations allowed on the value.
Below is a comprehensive reference of the primary fundamental data types used in C programming, their format specifiers, memory sizes, and valid ranges.
Fundamental Data Types Reference Table
| Keyword | Format Specifier | Size (Bytes) | Data Range |
|---|---|---|---|
| char | %c | 1 Byte | -128 to +127 |
| int | %d | 2 Bytes | -32,768 to +32,767 |
| long int | %ld | 4 Bytes | -2,147,483,648 to +2,147,483,647 (-2³¹ to +2³¹ - 1) |
| unsigned int | %u | 2 Bytes | 0 to 65,535 |
| float | %f | 4 Bytes | -3.4e38 to +3.4e38 |
| double | %lf | 8 Bytes | -1.7e38 to +1.7e38 |
| long double | %Lf | 12 – 16 Bytes | -3.4e38 to +3.4e38 |
Practical Usage Notes
- Use char for storing single ASCII characters or very small integers.
- Use int for counting, index loops, and whole numbers.
- Use float or double when high precision floating-point fractions are required.
- Use unsigned specifiers when negative values are never expected, effectively doubling the positive range.