Float and Double in C

Float and Double:

On this page we will discuss about float and double in C programming language.

Float and Double in C

Definitions:

Float

  • This is typically used for graphic-based libraries since it makes it easier for compilers to manage your programs’ processing capacity.
  • Float has single precision.
  • The storage required by Float is 4 bytes.
  • Float variables can be given a value with a range of 1.2E-38 to 3.4E+38.
  • It features a 32-bit floating point precision, according to IEEE.
  • It has a precision of six decimal places.

Double

  • In programming languages, this is the most used data type for assigning values with a real or decimal-based number within, such 3.14 for pi.
  • It has two times as much precision as a float, or double precision.
  • Double type variables can be given a value that falls between the ranges of 2.3E-308 and 1.7E+308.
  • Double requires storage of 8 bytes.
  • It has a precision of 15 decimal places.
  • It features a 64-bit floating point precision, according to IEEE.

Example of Float:

Run
#include<stdio.h>
int main()
{
    float a = 22.45;
    printf("Value of a = %f\n",a);
    return 0;
}

Output:

Value of a = 22.450001

Example of Double:

Run
#include<stdio.h>
int main()
{
    double d = 567.89732;
    printf("Value of d = %f\n",d);
    return 0;
}

Output:

Value of d = 567.897320

Example of Float and Double:

Run
#include<stdio.h>
int main()
{
    int a = 20, b = 10, sum;
    float c = 22.22, d = 22.22, add;
    sum = a+b;
    add = c+d;
    printf("The sum of a and b is = %d\n", sum);
    printf("The sum of c and d is = %d", add);
    return 0;
}

Output:

The sum of a and b is : 37
The sum of c and d is : -11046240

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription