Floating-Point Literals

These are used to represent and store real numbers. The real number has an integer part, real part, fractional part, and exponential part. The floating-point literals can be stored either in decimal form or exponential form. While representing the floating-point decimals one must keep two things in mind to produce valid literal:

  • In the decimal form, one must include the integer part, or fractional part, or both, otherwise, it will lead to an error.
  • In the exponential form, one must include both the significand and exponent part, otherwise, it will lead to an error.

A few floating-point literal representations are shown below:

Valid Floating Literals:

10.125
1.215e-10L
10.5E-3

Invalid Floating Literals:

123E
1250f
0.e879

Example:

C




#include <stdio.h>
 
int main()
{
    // constant float literal
    const float floatVal = 4.14;
 
    printf("Floating point literal: %.2f\n",
        floatVal);
    return 0;
}


Output

Floating point literal: 4.14




Literals in C

In C, Literals are the constant values that are assigned to the variables. Literals represent fixed values that cannot be modified. Literals contain memory but they do not have references as variables. Generally, both terms, constants, and literals are used interchangeably. 
For example, “const int = 5;“, is a constant expression and the value 5 is referred to as a constant integer literal.

Similar Reads

Types of C Literals

There are 4 types of literal in C:...

1. Integer Literals

Integer literals are used to represent and store the integer values only. Integer literals are expressed in two types i.e....

2. Floating-Point Literals

...

3. Character Literals

These are used to represent and store real numbers. The real number has an integer part, real part, fractional part, and exponential part. The floating-point literals can be stored either in decimal form or exponential form. While representing the floating-point decimals one must keep two things in mind to produce valid literal:...

4. String Literals

...