Home > Article > Backend Development > How does the `LL` suffix enable handling large integer values in C/C when the `long` data type is insufficient?
long long in C/C
This code snippet demonstrates the use of the long long data type in C/C :
#include <stdio.h> int main() { int num1 = 1000000000; long num2 = 1000000000; long long num3; long long num4 = ~0; printf("%u %u %u", sizeof(num1), sizeof(num2), sizeof(num3)); printf("%d %ld %lld %llu", num1, num2, num3, num4); return 0; }
When compiling the code with the commented line uncommented (assigning a value that is too large for the long data type), an error occurs:
error: integer constant is too large for long type
This is because the value 100000000000 is too large for the long data type, and the compiler requires a suffix to explicitly specify the long long data type. To resolve this issue, add the LL suffix to the literal:
long long num3 = 100000000000LL;
The LL suffix indicates that the literal should be treated as a long long value. When the code is compiled and executed, it produces values that are larger than 10000000000, which demonstrates the extended range of the long long data type.
The above is the detailed content of How does the `LL` suffix enable handling large integer values in C/C when the `long` data type is insufficient?. For more information, please follow other related articles on the PHP Chinese website!