I have this constant:
#define MAX_DATE 2958465L
What does the L mean in this sense?
I have this constant:
#define MAX_DATE 2958465L
What does the L mean in this sense?
It is a long
integer literal.
Integer literals have a type of int
by default; the L
suffix gives it a type of long
(Note that if the value cannot be represented by an int
, then the literal will have a type of long
even without the suffix).
int
, long int
(C++03 §2.13.1/2). –
Galimatias L
suffix ourselves? –
Volscian 42
is an int
. If you want it to be a long
, you need to add the L
(giving 42L
). There are many reasons that you might want a long
explicitly: you might do it to select a particular function overload or to ensure a template is instantiated with long
instead of int
. You might use it to ensure some integer expression is evaluated with long
precision instead of int
precision. INT_MAX + 1
will overflow. If long
has greater range than int
, INT_MAX + 1L
will not overflow. –
Galimatias In this scenario the L
does nothing.
The L
after a number gives the constant the long
type, but because in this scenario the constant is immediately assigned to an int
variable nothing is changed.
L tells the compiler that the number is of type Long. Long is a signed type greater than or equal to an int in size. On most modern compilers, this means that the number will take 4 bytes of memory. This happens to be the same as an int on most compilers so it won't have an effect in this case.
see this link it says :
Literal constants (often referred to as literals or constants) are invariants whose values are implied by their representations.
base:decimal
example:1L
description: Any decimal number (digits 0-9) not beginning with a 0 (zero) and followed by L or l
© 2022 - 2024 — McMap. All rights reserved.