What is the meaning of "l" in some variable initialisations? For example:
#define maxpossible (1000000000L)
double A = 1L;
double B = 999999999l;
Is there a difference between "L" and "l"?
What is the meaning of "l" in some variable initialisations? For example:
#define maxpossible (1000000000L)
double A = 1L;
double B = 999999999l;
Is there a difference between "L" and "l"?
This is a suffix type specifier, for A
and B
you can read more about floating point literals here. The short answer is that L
and l
both indicate long double
. For maxpossible
you can read about integer literal here and L
indicates long
.
EDIT
As Mike Seymour kindly pointed out all of the literals are integer
literals. This just goes to show that the times when you do not sanity check your answer, you will say something wrong. A simple sanity check would have been as follows:
#include <iostream>
#include <typeinfo>
int main()
{
std::cout << typeid( decltype( 1L ) ).name() << std::endl ;
std::cout << typeid( decltype( 999999999l ) ).name() << std::endl ;
std::cout << typeid( decltype( 1000000000L ) ).name() << std::endl ;
}
Which gives me l
for each one and running that through c++filt -t
gives me long
. What would have made the literals floating point literals? Either a:
4e2
For example:
std::cout << typeid( decltype( .1l ) ).name() << std::endl ;
std::cout << typeid( decltype( 1e2L ) ).name() << std::endl ;
Which gives me e
for both cases and running that through c++filt -t
gives me long double
.
since These are literal constants.
The suffix l
or L
makes the constant be long
or long double
.
In your example, maxpossible
is a long integer
. A
and B
are both long doubles. But since you are declaring them as double
, they are stored as doubles
.