Skip to main content
Engineering LibreTexts

4.4.2: Literals and Constants - Floating Point

  • Page ID
  • Floating-Point Literals

     These are used to represent and store real numbers. The real number has an integer part, real part, fractional part and an 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 literals:

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

    Few floating-point literal representations are shown below:

    Valid Floating Literals:


    Invalid Floating Literals:



    #include <iostream> 
    using namespace std; 
    int main() 
    {   // Real literal 
        const float floatVal = 4.14; 
        cout << "Floating-point literal: " << floatVal << "\n"; 
        return 0; 


    Floating point literal: 4.14

     Adapted from:
    "Types of Literals in C/C++ with Examples" by Chinmoy LenkaGeeks for Geeks