Share:
Notifications
Clear all

What is the difference between int, float, double, and char in C

1 Posts
1 Users
0 Reactions
855 Views
(@kajal)
Posts: 299
Reputable Member
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-byte int (using 32-bit architecture).
  • Example:
    int num = 5;

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:
    float pi = 3.14;

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:
    double pi = 3.141592653589793;

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:
    char letter = 'A';

 

 
Posted : 16/03/2025 9:15 pm
Share: