最近在看深入理解计算机系统这本书,上面提到了在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位机器各个类型变量所占字节数:

  C类型            32               64
    char             1                1
    short int             2                2
    int             4                4
    long int             4                8
    long long int             8                8
    char*             4                8
    float             4                4
    double             8                8

需要说明一下的是指针类型存储的是所指向变量的地址,所以32位机器只需要32bit,而64位机器需要64bit。

最新文章

  1. SQL Azure (18) 使用External Table实现垮库查询
  2. Visual Studio 2015初体验——前端开发工作的问题
  3. poj1743 后缀数组求不可重叠的重复出现的子串最长长度
  4. 深入理解css中position属性及z-index属性
  5. DAO接口及实现类
  6. 微信微博分享注意事项(sharesdk)
  7. Java Concurrency - Phaser, Controlling phase change in concurrent phased tasks
  8. NOSQL之【redis的主从复制】
  9. Contest2037 - CSU Monthly 2013 Oct (problem F :ZZY and his little friends)
  10. Netbeans代码配色主题大搜集
  11. 二、linux文件系统之linux启动
  12. phpcms v9联动菜单的调用方法_详解get_linkage函数
  13. 在VS2010上使用C#调用非托管C++生成的DLL文件
  14. Hexo server报错TypeError: Cannot read property 'utcOffset' of null解决方法
  15. 设置Vmware中Kali_linux 共享文件夹
  16. commit your changes or stash them before you can merge
  17. 我理解的NODE
  18. DevExpress WPF入门指南:DXWindow应用
  19. FA_会计中的折旧方式的种类(概念)
  20. Codeforces Round #528 Solution

热门文章

  1. linux 创建数据库
  2. RabbitMQ的四种ExChange
  3. javascript总结31 :DOM概述
  4. CodeForces 540B School Marks (贪心)
  5. CVPR,ICCV和ECCV,计算机视觉三大顶级盛会
  6. Alpha冲刺(四)
  7. Elasticsearch 5.6.5 安装head插件
  8. Android-ListView-ArrayAdapter
  9. [LeetCode 题解]: Permutations
  10. Transaction And Lock--两种方式实现可重复读