Topic starter
In C, int
, float
, double
, and char
are different data types used to store different kinds of values. Here's a breakdown of the differences:
1. int
(Integer):
- Purpose: Used to store whole numbers (i.e., integers without any decimal points).
- Size: Typically 4 bytes on most systems (but can vary depending on the system architecture).
- Range: The range of values
int
can hold depends on the system, but generally, it is from -2,147,483,648 to 2,147,483,647 for a 4-byteint
(using 32-bit architecture). - Example:
2. float
(Floating-point number):
- Purpose: Used to store numbers with a fractional part (decimals). It is used when precision is not as critical, and space is a concern.
- Size: Typically 4 bytes (32 bits).
- Range: Can store numbers from approximately 1.5 × 10⁻⁴⁵ to 3.4 × 10³⁸ with about 6-7 decimal digits of precision.
- Example:
3. double
(Double-precision floating-point number):
- Purpose: Used for storing floating-point numbers with greater precision than
float
. It is used when more accuracy is required. - Size: Typically 8 bytes (64 bits).
- Range: Can store numbers from approximately 5.0 × 10⁻³²⁷ to 1.7 × 10³⁰⁷ with about 15-16 decimal digits of precision.
- Example:
4. char
(Character):
- Purpose: Used to store a single character (usually one byte).
- Size: Typically 1 byte (8 bits).
- Range: Can store values from -128 to 127 (signed) or 0 to 255 (unsigned) if used as a numeric type. When used as a character, it represents a single character, e.g., 'A', 'b', '3', etc.
- Example:
Posted : 16/03/2025 9:15 pm