int 占一个机器字长

int与short int是不一样的。 

C++标准规定,int占一个机器字长。在32位系统中int占32位,也就是4个字节,

而在老式的16位系统中,int占16位,即2个字节。

而C++标准中只限制规定short int不能超过int的长度,具体长度的可以由C++编译器的实现厂商自行决定。目前流行的32位C++编译器中,

通常int占4字节,short int占2字节。其中short int可以简写为short。类似地,C++标准只限制了long int不得小于int的长度,具体也没有作出限制。

应该和CPU构架和编译系统有关吧。呵呵。
这个问题我也很模糊!!!

我的32位机器VC++结果是


短整形short int = 16 位 = 2 字节
整形int = 32 位 = 4 字节
长整形long int = 32 位 = 4 字节
单精度float = 32 位 = 4 字节
双精度double = 64 位 = 8 字节
长整形双精度long double = 64 位 = 8 字节
字符型char = 8 位 = 1 字节
无符号字符型unsigned char = 8 位 = 1 字节
有符号字符型signed char = 8 位 = 1 字节
无符号整形unsigned int = 32 位 = 4 字节
有符号整形signed int = 32 位 = 4 字节
无符号长整形signed long int = 32 位 = 4 字节

在TC2.0中

short int = 16 Bit = 2 Byte
int = 16 Bit = 2 Byte
long int = 32 Bit = 4 Byte
float = 32 Bit = 4 Byte
double = 64 Bit = 8 Byte
long double = 80 Bit = 10 Byte
char = 8 Bit = 1 Byte
unsigned char = 8 Bit = 1 Byte
signed char = 8 Bit = 1 Byte
unsigned int = 16 Bit = 2 Byte
signed int = 16 Bit = 2 Byte
signed long int = 32 Bit = 4 Byte

tc的
long double = 80 Bit = 10 Byte
vc++的
long double = 64 位 = 8 字节

差了2个字节

我总结应该是和编译系统有关,编译系统根据机器定义。
还要遵循short int <= int <= long int 吧

原文地址:https://www.cnblogs.com/mjorcen/p/3813580.html