long long int
Type
This page was translated by a robot.
The specification long longis a modification of the inttype . A long long intstores an integer value, which nowadays is usually encoded with 64 bits. Whenever possible, an integer type with an explicit number of bits from the stdintlibrary should be used instead of this type.
Details
A long long intor short long longis encoded on today's common systems with 64 bits. However, this size specification is not guaranteed, but is only given on this page as a guideline, even if, especially on older systems, a long longwas sometimes only coded with 32 bits or was not available at all. The type long longwas introduced with the C99 standard and denotes a truly long integer in the sense that the largest possible integer of this type inthas many more digits compared to a normal one.
The guy long long longis too long.
Today, type modifiers such as short, longor long longare used less and less, since many integer types with more precise information on the number of bits are available from the C99 standard with the stdintlibrary .
A long longtype can be modified with either signedor . unsignedDepending on the case, a stores long longeither negative as well as positive values, or explicitly only positive ones. If the modifier is omitted, it is signedassumed by the compiler by default. longIt doesn't matter whether the modifier comes before or after the type and whether the two keywords are next to each other. Likewise, it doesn't matter where the type identifier intis, or if it's actually omitted.
Positive values are stored as a binary integer . The negative values of a are usually encoded signed long longusing two's complement on today's computers.
The maximum and minimum possible values of a long longare defined in the limitslibrary .
If the value range of one is exceeded by an arithmetic operation long long, this is referred to as an overflow . On today's processors, a signed integer suddenly flips from the positive to the negative range, and in the case of unsigned integers, the number 0(zero) suddenly follows the maximum value. This is called a wrap around . Similarly, falling below the value range is referred to as underflow and the wrap-around happens vice versa. However, there is no guarantee that this effect will occur on every system.
When specifying fixed values in the source code, long longvalues should be small llor large LLas a suffix. Both suffixes mean the same thing, but the capital letter variant is always used on this page so that there is no 11risk of confusion with the sequence of digits (one-one).
9999999987654321ll
9999999987654321LL
9999999987654321
To explicitly unsignedmark a fixed value as , the suffix ucan be used.
Today's compilers usually issue warnings when fixed values are too large for a intand should be suffixed as a long long. Some compilers even issue a warning if a number is so large that it cannot be signed long longstored more than . If a number even unsigned long longexceeds the value range of one, a warning (but not necessarily an error) is also issued. The behavior of such a large number during runtime is undetermined.
To print or read in the modifier long long( two small ) is used:printfscanfllL
Arithmetic Conversion
In the case of assignments, initializations or casts to a long longtype, the compiler may perform arithmetic conversions . The conversion rules for the long longtype are described below. In the case of unsafe conversions, a compiler usually issues a warning, which can be suppressed using an explicit cast if necessary.
When converting a floating point type to a floating point type long long, the decimal places are simply truncated (rounding towards zero).
If the floating point number to be converted has no place in a long long, the result is undefined. On today's systems, the maximum or minimum possible value is often assumed.
9223372036854775807
-9223372036854775808
18446744073709551615
0
The result can vary depending on the system. The values given here correspond to the values on the author's system.
When converting an integer type to an long long, the value and the sign are preserved exactly in the most important cases:
The conversion of an integer value into an long long, which is not included in the value range, is not defined. However, the following usually happens on today's systems: If the value to be assigned has the same number or more bits, then all those lowest-order bits of the value to be assigned are copied bit-exactly, which long longcan be accommodated in the type. If the value to be assigned has fewer bit positions, the available bit positions are long longcopied to the least significant bit positions of the . The non-defined higher-order bit positions are filled as follows: If the type of the value to be assigned is unsigned, all non-defined bit positions are filled with the bit0copied. If the type of value to be assigned is signed, the most significant bit of the available bit positions is copied to all high-order bit positions.
Because of these rules, the following cases can lead to incorrect values: A signed number cannot be converted correctly to an unsigned type. Too large an unsigned number can result in negative values when cast to a signed type.
18446744073709551493
-8446744073709551616
A Javascript program to illustrate the effects of cutting off bits can be found at Number System Converter .