First, we want to understand the meaning of "bit", "byte", "word" (word), these three.
bit is the smallest unit of storage and can only be placed in a machine language of 0 or 1.
Byte (byte), 8 bits (bit) is a byte, so 1 bytes = 8 bits, 4 bytes is 32 bits.
The length of Word (word) is related to computer performance, such as a 16-bit computer, whose word length is 2 bytes, 32-bit computers, and a length of 4 bytes.
General situation:
1, int usually represents the natural length of a certificate in a particular machine.
2, long long type is 64 bits, long type bit 32 bit, short type is 16 bits, int type is 16 bit or 32 bit.
3, in principle, these four types represent 4 different size values.
4, each compiler can choose the appropriate type length according to the hardware characteristics, but to adhere to the following restrictions: Shortand int type at least 16 bits, long type is at least 32 bits, and the short type must not be longer than the int type, and the int type must not be longer than the long type.
5, in general, the short type is half the machine word length, the int type is a machine length, and the long type is one or two machine word length (in 32-bit machine int type and long type are usually the same word length). See the explanation of the length of the word above.
Type |
16-bit System/byte |
32-bit System/byte |
64-bit System/byte |
Char |
1 |
1 |
1 |
char* |
2 |
4 |
8 |
Short |
2 |
2 |
2 |
Int |
2 |
4 |
4 |
Long |
4 |
4 |
8 |
Long Long |
8 |
8 |
8 |
As you can see from the table, the int type is 4 bytes and 32 bits under a 64-bit system. And what exactly is this thing related to? Who's in control? From the Internet grilled a variety of explanations, there are about two points:
1, 64-bit system, the compiler in order to forward compatibility, the int type is automatically compiled into 4 bytes;
2, these things are compiler to control, different compiler will compile int type to different length, so, use what compiler is important, such as: 32 bit system, TC int is 16 bit length, VC is 32 bit length. If your system is 64, then the compiler software default installation path has program File (x86), which is the 32-bit compiler.
3, long Long is the standard 8 bytes, is not limited by the compiler, so 16-bit is still 8 bytes.
4, we are careful when using integer variables, especially when it takes up space, do not take it for granted that int is 4 bytes under a 32-bit system. Try to use the sizeof value.
Content about Short,int,long