float, double

Specifier Description
float Allocates 4 bytes of data storage.
double Allocates 8 bytes of data storage.
long double Normally allocates 8 bytes of data storage. If the ldbl128 or longdouble compiler options are in effect, 16 bytes of data storage are allocated.
Allocates 16 bytes of data storage.
Notes:
  1. The amount of storage allocated for a float, double, or long double floating-point variable is implementation-dependent. On all compilers, the storage size of a float variable is less than or equal to the storage size of a double variable.
  2. In extended mode, the C compiler supports long float, but this is a non-portable language extension.

To declare a data object having a floating-point type, use the float specifier.

The float specifier has the form:

The declarator for a simple floating-point declaration is an identifier. You can initialize a simple floating-point variable with a float constant or with a variable or expression that evaluates to an integer or floating-point number. The storage class of a variable determines how you initialize the variable.

The following example defines the identifier pi as an object of type double:

double pi;

The following example defines the float variable real_number with the initial value 100.55:

static float real_number = 100.55f;

The following example defines the float variable float_var with the initial value 0.0143:

float float_var = 1.43e-2f;

The following example declares the long double variable maximum:

extern long double maximum;

The following example defines the array table with 20 elements of type double:

double table[20];


Lexical Elements - Floating-Point Constants


ldbl128, longdouble Compiler Option