Lesson 6: Fundamental Data Types: Integers
Data types specify the type of data a variable can hold and the amount of memory it occupies.
The int Type
Integers are used to store whole numbers (positive, negative, or zero) without fractional parts.
The basic integer type is int. Its size is usually 4 bytes (32 bits), allowing it to store values typically from -2 billion to +2 billion.
Integer Type Qualifiers
C offers qualifiers to manage the size and sign of integers:
| Type | Description | Typical Size (Bytes) |
|---|---|---|
short int | Smaller integer | 2 |
int | Standard integer | 4 |
long int | Larger integer | 4 or 8 |
long long int | Largest integer (C99+) | 8 |
Signed vs. Unsigned
- Signed (default): Can hold positive and negative numbers.
- Unsigned: Can only hold non-negative numbers (0 and positive). This doubles the positive range but eliminates negative values.
c // Examples of declarations int age = 30; // Signed int unsigned int counter = 100000; // Only positive values short int small_number = -5; long long big_number = 9000000000LL; // Use LL suffix for long long
Note: The exact size of these types can vary slightly between different compilers and architectures, but the relationships (short <= int <= long <= long long) hold true.