Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

float — floating-point type

float stores floating-point numbers with limited precision. C does not guarantee a 32-bit representation.

Version: C23; repository compiler flag, production runtime not attested

Syntax

float name = 2.0f;

float is a real floating-point type. Not every decimal value is represented exactly; calculations can round results. C requires neither 32 bits nor IEEE 754 binary32. Macros in <float.h> describe the implementation; FLT_DIG is at least 6.

The f suffix gives a constant such as 2.0f type float; unsuffixed 2.0 has type double. In a printf call, a float argument is promoted to double, and %.1f prints one digit after the decimal separator. The values 2, 3, and 6 are exactly representable as float, but C23 leaves the accuracy of floating-point multiplication implementation-defined. The output 6.0 shows what the program printed in the tested environment, not that the multiplication produces an exact result on every conforming implementation.

Examples

#include <stdio.h>

int main(void)
{
    float width = 2.0f;
    float height = 3.0f;
    float area = width * height;

    printf("%.1f\n", area);
    return 0;
}

Result

6.0

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources