• C/C++基本数据类型所占字节数


    关于这个主要的问题,非常早曾经就非常清楚了,C标准中并没有详细给出规定那个基本类型应该是多少字节数,并且这个也与机器、OS、编译器有关,比方相同是在32bits的操作系统系,VC++的编译器下int类型为占4个字节;而tuborC下则是2个字节。


    所以int,long int,short int的宽度都可能随编译器而异。但有几条铁定的原则(ANSI/ISO制订的):


    • sizeof(short int)<=sizeof(int)

    • sizeof(int)<=sizeof(long int)

    • short int至少应为16位(2字节)

    • long int至少应为32位。


    以下给出不同位数编译器下的基本数据类型所占的字节数:



    16位编译器


    char :1个字节
    char*(即指针变量): 2个字节
    short int : 2个字节
    int:  2个字节
    unsigned int : 2个字节
    float:  4个字节
    double:   8个字节
    long:   4个字节
    long long:  8个字节
    unsigned long:  4个字节



    32位编译器


    char :1个字节
    char*(即指针变量): 4个字节(32位的寻址空间是2^32, 即32个bit,也就是4个字节。同理64位编译器)
    short int : 2个字节
    int:  4个字节
    unsigned int : 4个字节
    float:  4个字节
    double:   8个字节
    long:   4个字节
    long long:  8个字节
    unsigned long:  4个字节


    64位编译器

    char :1个字节
    char*(即指针变量): 8个字节
    short int : 2个字节
    int:  4个字节
    unsigned int : 4个字节
    float:  4个字节
    double:   8个字节
    long:   8个字节
    long long:  8个字节
    unsigned long:  8个字节

  • 相关阅读:
    code review
    自我封闭
    怎么验证?
    DRUPAL点滴
    CRLF CSRF XSS
    各种element/format 在manage display 下的选项
    html list <==> unformatted list
    ctrl + d 在phpstorm 和 eclipse 中的不同含义
    常量和变量的区别
    JSON和php里的数据序列化
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/3740466.html
Copyright © 2020-2023  润新知