Float data type in C

Previous
Next

Float types:

  • floating point type variable is a variable that can hold a real number, such as 4.0, 2.5, 3.33, or 0.1226.
  • There are three different floating point data types: floatdouble, and long double.
  • A float is usually 4 bytes and a double 8 bytes, but these are not strict requirements, so sizes may vary.
  • Long doubles were added to the language after its release for architectures that support even larger floating point numbers.

These can have positive or negative values:

  1. Float: The basic floating-point type for the system; it can represent at least six significant figures accurately.
  2. Double: A (possibly) larger unit for holding floating-point numbers. It may allow more significant figures (at least 10, typically more) and perhaps larger exponents than float.
  3. Long double: A (possibly) even larger unit for holding floating-point numbers. It may allow more significant figures and perhaps larger exponents than double.
#include<stdio.h>
void  main()
{
	float me = 1.1;
	double you = 1.1;
	if(me==you)
		printf("C is easy");
	else
		printf("Need to analyze");
}

Floating-Point Constants

  • There are many choices open to you when you write a floating-point constant.
  • The basic form of a floating-point constant is a signed series of digits, including a decimal point, followed by an e or E, followed by a signed exponent indicating the power of 10 used.

Here are two valid floating-point constants:

                        -1.56E+12

                        2.87e-3

Previous
Next

Add Comment

Courses Enquiry Form