In C language, how will you treat the constant 3.14 explicitly as a long double literal? Add the correct type suffix to the numeric constant so the compiler stores it as long double.

Difficulty: Easy

Correct Answer: use 3.14L

Explanation:


Introduction:
In C programming, floating constants can be forced to a particular floating type by adding a suffix. This question checks whether you know the correct suffix to create a long double literal from a decimal number like 3.14.


Given Data / Assumptions:

  • Literal: 3.14
  • Goal: make it a long double
  • Environment: standard C syntax for literal suffixes


Concept / Approach:
By default, an unsuffixed floating constant such as 3.14 is of type double. C allows suffixes to change the type: 'f' or 'F' yields float, and 'l' or 'L' yields long double. No other multi-letter combinations apply to decimal floating constants.


Step-by-Step Solution:
1) Start with the constant 3.14 (type: double by default).2) To request long double, append the uppercase L suffix.3) The resulting token 3.14L is parsed as type long double by the compiler.4) No additional casts are required when the literal itself has the desired type.


Verification / Alternative check:
You can confirm by using sizeof with the literal in an expression context or by assigning it to a long double variable and observing that no narrowing conversion occurs.


Why Other Options Are Wrong:
3.14LD: 'LD' is not a valid suffix; only 'L' is defined for long double.3.14DL: 'DL' is not a recognized suffix pattern.3.14LF: Combining 'L' and 'F' is invalid for decimal floating constants.


Common Pitfalls:
Using lowercase 'l' can be confused with '1' in some fonts; prefer uppercase 'L' for clarity. Do not add two-letter combinations such as 'LD' expecting them to work; the standard specifies single-letter suffixes.


Final Answer:
use 3.14L

More Questions from Floating Point Issues

Discussion & Comments

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