????????最近在看深入理解計算機系統這本書,上面提到了在32位機器和64機器中int類型都占用4個字節。后來,查了The C Programming language這本書,里面有一句話是這樣的:Each compiler is free to choose appropriate sizes for its own hardware, subject only to the restriction that shorts and ints are at least 16bits, longs are at least 32bits, and short is no longer than int, which is no longer than long.意思大致是編譯器可以根據自身硬件來選擇合適的大小,但是需要滿足約束:short和int型至少為16位,long型至少為32位,并且short型長度不能超過int型,而int型不能超過long型。這即是說各個類型的變量長度是由編譯器來決定的,而當前主流的編譯器中一般是32位機器和64位機器中int型都是4個字節(例如,GCC)。下面列舉在GCC編譯器下32位機器和64位機器各個類型變量所占字節數:
????????????需要說明一下的是指針類型存儲的是所指向變量的地址,所以32位機器只需要32bit,而64位機器需要64bit。
轉自:http://blog.51cto.com/charlesxie/939680