在C/C++中,int、char、double、long所占的字节数

来源:互联网 发布:淘宝0.01刷手机 编辑:程序博客网 时间:2024/05/23 21:34

所占字节数和机器字长及编译器有关:
所以,intlong intshort int的宽度都可能随编译器而异。但有几条铁定的原则(ANSI/ISO制定的):

sizeof(short int) <= sizeof(int)sizeof(int) <= sizeof(long int)short int至少为16bit(2byte)long int 至少应为32byte

16位编译器

char             1bytechar*            2byteshort int        2byteint              2byteunsigned int     2bytefloat            4bytedouble           8bytelong             4bytelong long        8byteunsigned long    4byte

32位编译器

char             1bytechar*            4byteshort int        2byteint              4byteunsigned int     4bytefloat            4bytedouble           8bytelong             4bytelong long        8byteunsigned long    4byte

64位编译器

char             1bytechar*            8byteshort int        2byteint              4byteunsigned int     4bytefloat            4bytedouble           8bytelong             8bytelong long        8byteunsigned long    8byte

char*表示指针变量,它存的是变量的地址,所以在同一编译器下,不管是char*还是int*,它们所占位数都是相同的。
32位的寻址空间是2^32,即32bit,也就是4byte,所以32位编译器中char*(指针变量)占4byte。同理64位编译器占8byte

0 0
原创粉丝点击