Original address:
http://blog.sina.com.cn/s/blog_6f62c9510101svjz.html#cmt_3221642
Original:
Suddenly think of a long and int exactly what difference (found that there are many problems are suddenly thought of), and then Baidu, Google a variety of search, all kinds of books: "C + + Primer", "C programming Language" view, finally understand some. The following words are selected from the C programming language:
The introduction of the short and long two qualifiers gives us the number of different lengths of shaping that meet the actual needs. An int typically represents the natural length of a certificate in a particular machine. The short type is typically 16 bits, the long type is usually 32 bits, and the int type can be 16-bit or 32-bit. Each compiler can choose the appropriate type length according to the hardware characteristics, but the following restrictions apply: the short and int types are at least 16 bits, the long type is at least 32 bits, and the short type is not longer than the int type, and the int type is not longer than the long type.
The following paragraph is selected from "C + + Primer":
The short, int, and long types all represent integer values, and the size of the storage space is different. Generally, 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 lengths (in 32-bit machines the int type and the long type are usually the same word length).
At this time I thought again, different machine bit, these three types exactly what difference, short does not say, from the above two paragraph introduction, short should be 16 bit, then int and long? Baidu a bit (I do not like Baidu, but Google is not stable, only Baidu). Look at the list first:
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.
3, long Long is the standard 8 bytes, is not limited by the compiler, so 16-bit is still 8 bytes. (More Cheboyou 0_0i_i)
Through the above introduction, we should understand the definition of the integral type, so we have to use the integer variable time is careful, especially when it takes up the space length, do not assume that int in 32-bit system is 4 bytes. Try to use the sizeof value.
The difference between "go" long and int