Floating point literal in C++

In this tutorial, you will learn about floating point literals in C++.

Before proceeding to floating point literals, let us have a brief introduction of what are literals and their types.

Constants are referred to as the fixed values of the constant variables of the program that may not be altered. They are also called literals.

Example: Constant literal

const int a=10;

This expression is an example of constant expression where the value 10 is referred to as constant integer literal.

Literals can be of any of  the basic/primitive data types and can be divided into the following categories in C++:

  1. Integer-type
  2. Floating-type
  3. Character-type
  4. Strings
  5. Boolean Values

Now, let us move to Floating-Point Literals.

Floating-Point Literals are used so as to store and represent real numbers. A real number consists of an integer part, a decimal point, a fractional part, and an exponential part. Floating-point literals can be represented in either of the two forms:

  1. Decimal form:  While representing in this form you should include the decimal point or the exponent or both
  2. Exponential form:  While representing in this form you should include the integer part or the fractional part or both. The signed exponent is represented by the symbol e or E.

Below are some examples to demonstrate the correct  and some incorrect representations of floating-point literals:

3.1416  //correct
1.0125E-12 //correct
12.4e-5 //correct


121e //incorrect
201E //incorrect
e.089 //incorrect
0.e77 //incorrect

At a glance, I hope that this tutorial helps you to better understand the notion behind constants(or literals) as well as of floating point literals.

Leave a Reply

Your email address will not be published. Required fields are marked *