Floating-Point Literals
The Floating-point literals in C++ are constants that represent numbers with the fractional or decimal part. These can be either single-precision or double-precision values.
Like integer literals, the floating point literals can also be defined as double or float by using suffix (no suffix) and f respectively. By default, all the fractional numbers are considered to be of type double by C++ compiler.
Example
double floatLiteral = 3.14;
Implementation
C++
// C++ program to illustrate the floating point literals #include <iostream> using namespace std; int main() { // float literal float e = 2.7f; // double literal double pi = 3.14; // long double literal long double g = 9.8L; cout << "The Value of pi: " << pi << endl; cout << "The value of e: " << e << endl; cout << "The value of g: " << g << endl; return 0; } |
The Value of pi: 3.14 The value of e: 2.7 The value of g: 9.8
Literals In C++
In C++ programming language, we use literals to represent fixed values. C++ supports various types of literals including integer literals, floating-point literals, character literals, and string literals. In this article, we will discuss all the necessary information on C++ literals and their usage.