`float` — C++ Keyword
`float` — C++ Keyword
The float keyword in C++: a single-precision IEEE 754 floating-point type.
`float` — C++ Keyword
The float keyword in C++: a single-precision IEEE 754 floating-point type.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
floatA single-precision floating-point type. On all modern platforms this is a 32-bit IEEE 754 binary32 value, providing approximately 7 significant decimal digits.
float f;
float f = 3.14f; // 'f' suffix required for float literals
#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);
}
f suffix, a literal is double; assigning 3.14 to a float narrows from double.float when memory bandwidth matters (GPU, SIMD) or when storage is constrained.double.floatint 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;
}