Preface:
In a 16-bit environment, INT/unsigned int occupies 16 digits, and long/unsigned long occupies 32 digits.
In a 32-bit environment, int occupies 32 bits, unsigned int occupies 16 bits, and long/unsigned long occupies 32 bits.
When to use:
The range of long and Int Is [-2 ^ 31,2 ^ 31), that is,-2147483648 ~ 2147483647, while the unsigned range is [^ 32), that is, 0 ~ 4294967295, so the regular 32-bit integer can only process about 4 billion, when the number is more than 4 billion, it will use 64.
64-bit usage range:
Different compilers have different extensions for 64-bit integers. VC uses _ int64/unsigned _ int64 in the range of [-2 ^ 63, 2 ^ 63) and [9223372036854775808 ^ 64), that is ~ 9223372036854775807 and 0 ~ 18446744073709551615 (about 180 billion million ).
Note:
1. Different compilers lead to different declarations using 64-bit;
2. Long/unsigned long is generally a declaration method in Linux, such as: G ++
3. _ int64/unsigned _ int64 is usually a 64-bit declarative method in windows, such as:
4. Add ll to assign values explicitly when assigning values;
5. When the 64-bit and 32-bit mixed operations are performed, the 32-bit integer is implicitly converted to a 64-bit integer.
6. Output printf ("");, long uses % LLD output, __int64 uses % i64d, and u can replace d with unsigned characters.
7. After testing, the compiler generally supports two types of operations, so you don't have to worry too much about how to use them.
// ======================================== Gorgeous separation line ====== ==============================================
# Include <stdio. h>
# Include <stdlib. h>
Intmain (){
Unsigned long Longa = 412432424000ll;
Unsigned _ int64b = 9223372010954775808ll;
Printf ("% i64u \ n", a); // % LLD cannot be output normally, why? The answer is attached.
Printf ("% i64u", B );
System ("pause ");
Return 0;
}
Attached test results:
After the experiment, in vc6, Dev, and codeblocks, the C language can all use _ int64, and the output identifier is % i64d. However, if you add 2 L after the number in vc6, an error is returned. You can add only one or no more numbers. I checked the information, __int64 is for Windows and is supported by compilers such as Vc and GCC, but long and % LLD are required in UNIX and Linux. The latter is standard C!
I tried to use long with % i64d for correct output, but neither long or _ int64 with % LLD can be correctly output. So I come to the conclusion that in windows, Longlong or __int64 must be used with % 64d. In UNIX and Linux, the standard C-defined long must be used with % LLD.