How do you use long long in the C language?
In the C programming language, long long is a data type used to represent larger integer values. It typically occupies 8 bytes of storage space and can store a wider range of integers. Here is an example of using long long:
- Declare a variable as long long:
long long num1;
long long num2 = 1234567890123456789LL; // 使用LL后缀表示常量为long long类型
- perform calculations
long long result = num1 + num2;
long long product = num1 * num2;
- Output the value of a long long variable in a formatted manner.
printf("%lld\n", result);
It is important to note that different compilers may have varying lengths for the long long data type. You can use the sizeof operator to obtain the actual number of bytes for this type.
printf("long long类型的字节数:%d\n", sizeof(long long));
Although the long long data type can represent a larger range of integers, its range is still finite. The specific range of values can be viewed through the LLONG_MIN and LLONG_MAX constants in the limits.h header file.