float Single-precision floating-point type
float Single-precision floating-point type
float is single-precision, often 32-bit IEEE 754, not mandated. f suffix avoids double; approximation makes == unreliable, and varargs promote to double.
| Category | Type specifiers |
|---|---|
| Kind | Keyword / Statement |
| C standard | C89 / C90 |
📝 Syntax
float f = 3.14f;
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
ratio = 0.25
🏷️ Related type specifiers
📚 Related Tutorials
❓ FAQ
QHow do the types of 3.14 and 3.14f differ?
A3.14 has type double, while 3.14f has type float. Assigning the double literal to float requires another conversion, so an explicit f suffix avoids the unnecessary type difference.
QCan == be used to compare floating-point results for equality?
AMany decimal fractions have no exact binary floating-point representation, and rounding can give different values to mathematically equal expressions. Design comparisons around the problem's scale and error bounds; a small fixed epsilon is not universally suitable.
QCan printf's %f print a float directly?
AYes. A float passed as a variadic argument is promoted to double, which is exactly what %f expects. With scanf, use %f for a pointer to float and %lf for a pointer to double.