C Numeric Data Types
1. What are Numeric Data Types?
-
Numeric data types in C are used to store numbers, either whole numbers or decimal numbers.
-
They are broadly divided into:
-
Integer types → Whole numbers
-
Floating-point types → Decimal numbers
2. Integer Data Types
-
Used to store whole numbers (no fractions).
-
Memory size may vary depending on the compiler and system (typical for 32-bit system shown below).
| Type | Size (Typical) | Range (Approx) | Example |
|---|---|---|---|
int |
4 bytes | -2,147,483,648 to 2,147,483,647 | int a = 100; |
short int |
2 bytes | -32,768 to 32,767 | short b = 10; |
long int |
4–8 bytes | -2,147,483,648 to 2,147,483,647 | long c = 100000; |
long long |
8 bytes | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | long long d = 1000000000; |
unsigned |
varies | 0 to 4,294,967,295 | unsigned int u = 100; |
Example:
3. Floating-Point Data Types
-
Used to store numbers with fractional parts.
| Type | Size (Typical) | Example |
|---|---|---|
float |
4 bytes | float x = 3.14; |
double |
8 bytes | double y = 3.141592; |
long double |
10–16 bytes | long double z = 3.1415926535; |
Example:
Output:
-
%.nfor%.nlfis used to limit decimal places in output.
4. Key Points
-
Integer types store whole numbers; floating-point types store decimals.
-
Memory size affects range and precision.
-
Use
unsignedif only positive numbers are needed. -
Use
floatfor approximate decimals anddoublefor higher precision.
5. Combined Example
Output:
