What does LL mean?
It is specified in Paragraph 2.14.2 of the C++11 Standard:
2.14.2 Integer literals
[...]
long-long-suffix: one of
ll LL
Paragraph 2.14.2/2, and in particular Table 6, goes on specifying the meaning of the suffix for decimal, octal, and hexadecimal constants, and the types they are given.
Since 0
is an octal literal, the type of 0LL
is long long int
:
#include <type_traits>
int main()
{
// Won't fire
static_assert(std::is_same<decltype(0LL), long long int>::value, "Ouch!");
}
What is meant by LL as in 1000LL?
Copy-pasted from this question, which seems to be the exact same one with the ULL
suffix :
From the
gcc
manual:ISO C99 supports data types for integers that are at least 64 bits wide, and as an extension GCC supports them in C90 mode and in C++.
Simply writelong long int
for a signed integer, orunsigned long
for an unsigned integer. To make an integer constant of type
long int
long long int
, add the suffixLL
to the integer. To make an
integer constant of typeunsigned long long int
, add the suffix
ULL
to the integer.
It, indeed, is a suffix for the long long int
type.
What do 0LL or 0x0UL mean?
These are constants in C and C++. The suffix LL
means the constant is of type long long
, and UL
means unsigned long
.
In general, each L
or l
represents a long
and each U
or u
represents an unsigned
. So, e.g.
1uLL
means the constant 1 with type unsigned long long
.
This also applies to floating point numbers:
1.0f // of type 'float'
1.0 // of type 'double'
1.0L // of type 'long double'
and strings and characters, but they are prefixes:
'A' // of type 'char'
L'A' // of type 'wchar_t'
u'A' // of type 'char16_t' (C++0x only)
U'A' // of type 'char32_t' (C++0x only)
In C and C++ the integer constants are evaluated using their original type, which can cause bugs due to integer overflow:
long long nanosec_wrong = 1000000000 * 600;
// ^ you'll get '-1295421440' since the constants are of type 'int'
// which is usually only 32-bit long, not big enough to hold the result.
long long nanosec_correct = 1000000000LL * 600;
// ^ you'll correctly get '600000000000' with this
int secs = 600;
long long nanosec_2 = 1000000000LL * secs;
// ^ use the '1000000000LL' to ensure the multiplication is done as 'long long's.
In Google Go, all integers are evaluated as big integers (no truncation happens),
var nanosec_correct int64 = 1000000000 * 600
and there is no "usual arithmetic promotion"
var b int32 = 600
var a int64 = 1000000000 * b
// ^ cannot use 1000000000 * b (type int32) as type int64 in assignment
so the suffixes are not necessary.
using ``1ll(N-1)`` to assign a large number of value to a long long int variable
But what is this
1ll
?
The 1ll
is an integer literal. 1
is an an decimal literal and ll
is an integer suffix. The suffix ll
means that the type of the integer literal is long long int
. The 1
means that the value of the literal is, well, 1
.
And how is it able to store such large value?
I think you are asking about the line:
long long val = (1ll << (N - 1));
Because of the if (N >= 64) .. else
before, we know that N < 64
. So the maximum number could be:
1ll << 63 - 1 =
1ll << 62 =
0x4000000000000000
Which is just a number that fits in long long int
type. The long long int
type has at least 64 bits.
Without the ll
suffix, the 1
would have the type int
. On architectures where int
type is narrower then 64 bits, ex. 16 bits, then undefined behavior would happen. Left shifting a variable by a number greater or equal to the length in bits of the left operant is undefined behavior, see ex. this question.
If you are asking about the line :
ans = (ans + arr[i] % M) % M;
It is calculating the sum modulo #define M 1000000007
. It is common to do assignments/homework that calculate sum modulo this number, see ex this or this. The algorithm calculates the sum modulo 1000000007, not the whole number, that's why it is able to store it inside long long
variable.
What is 1LL or 2LL in C and C++?
The LL
makes the integer literal of type long long
.
So 2LL
, is a 2 of type long long
.
Without the LL
, the literal would only be of type int
.
This matters when you're doing stuff like this:
1 << 40
1LL << 40
With just the literal 1
, (assuming int
to be 32-bits, you shift beyond the size of the integer type -> undefined behavior).
With 1LL
, you set the type to long long
before hand and now it will properly return 2^40.
ULL suffix on a numeric literal
From the gcc
manual:
ISO C99 supports data types for integers that are at least 64 bits wide ( . . . ) . To make an integer constant of type
long long int
, add the suffixLL
to the integer. To make an integer constant of typeunsigned long long int
, add the suffixULL
to the integer.
These suffixes have also been added to C++ in C++11, and were already supported long long (pun intended) before that as compiler extensions.
what does L represent in any hex numberL
It means Long, as in, the type of the literal 0x03L is long
instead of the default int
. On some platforms that will mean 64 bits instead of 32 bits, but that's entirely platform-dependent (the only guarantee is that long is not shorter than int).
What does double bars (||) mean in SQL?
double bars are concatination:
select 'hello' || ' ' || 'world' from dual;
yields
'hello world'
Related Topics
How to Determine the Value of Socket Listen() Backlog Parameter
How to Output Array of Doubles to Hard Drive
Is There a Gcc Preprocessor Directive to Check If the Code Is Being Compiled on a 64 Bit MAChine
What Do the C and C++ Standards Say About Bit-Level Integer Representation and Manipulation
Eclipse Mingw C++ Cannot Find -Lpthread
What Are the Advantages and Disadvantages of Implementing Classes in Header Files
How to Config Cmake for Strip File
How to Find Substring from String
Conditionally Replace Regex Matches in String
How to Implement Readlink to Find the Path
Memoized, Recursive Factorial Function
Reading Directly from an Std::Istream into an Std::String
Convert Bitmap to Png In-Memory in C++ (Win32)
Using Std::Make_Unique with a Custom Deleter
C++: Std::Move with Rvalue Reference Is Not Moving Contents