`float` — C++ Keyword

`float` — C++ Keyword

The float keyword in C++: a single-precision IEEE 754 floating-point type.

How to use this reference page

Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.

  • Scan the top of the page first to identify the primary types, functions, or algorithm families involved.
  • Use the nearby-page links when your question is really about a companion header, related algorithm family, or broader subsystem.
  • Validate tricky behavior with a small compileable example before relying on memory for details like invalidation, ordering, allocation, or lifetime rules.

float

A single-precision floating-point type. On all modern platforms this is a 32-bit IEEE 754 binary32 value, providing approximately 7 significant decimal digits.

Syntax

float f;
float f = 3.14f;    // 'f' suffix required for float literals

Example

#include <print>
#include <cmath>
#include <cfloat>

int main() {
    float pi = 3.14159265f;
    float r  = 5.0f;

    std::println("{:.4f}", pi * r * r);   // ~78.5398

    // Precision limitation
    float x = 0.1f + 0.2f;
    std::println("{:.10f}", x);           // not exactly 0.3

    std::println("FLT_MAX: {:.2e}", FLT_MAX);  // ~3.40e+38
    std::println("FLT_EPSILON: {}", FLT_EPSILON);
}

Notes

Example in practice

int main() {
    // Pick one facility from this reference page.
    // Write the smallest program that exercises its main precondition,
    // complexity rule, or lifetime constraint before scaling up.
    return 0;
}