C literals: which option correctly represents a long double floating constant in standard C?

Difficulty: Easy

Correct Answer: 6.68L

Explanation:


Introduction / Context:
Floating constant suffixes control the type of a literal at compile time. Choosing the correct suffix helps avoid unintended promotions or loss of precision, especially when interfacing with math libraries and printf/scanf formats.



Given Data / Assumptions:

  • No unusual implementation-defined behavior; standard C suffix rules apply.
  • Default unsuffixed floating constants are of type double.


Concept / Approach:
In C, the suffix f or F yields type float; the suffix l or L yields type long double. No valid combined suffix “LF” exists for literals. Therefore, a long double constant corresponding to 6.68 must be written as 6.68L.



Step-by-Step Solution:
Consider 6.68 → default type double.Consider 6.68f or 6.68F → type float.Consider 6.68L → type long double.6.68LF → invalid suffix combination.



Verification / Alternative check:
Compilers report an invalid suffix for “LF”. Printing with printf requires matching format specifiers; long double uses %Lf.



Why Other Options Are Wrong:
6.68: double, not long double.6.68f / 6.68F: float, not long double.6.68LF: not a valid literal form.



Common Pitfalls:
Assuming uppercase F implies long double; forgetting to use the corresponding format specifier when printing long double values.



Final Answer:
6.68L

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion