OC:基本数据类型

作者: Kevin丨Wang | 来源:发表于2015-07-21 23:41 被阅读7048次
    基本类型

    类型限定修饰词

    除了上图中基本类型之外,还有一些类型限定修饰词

    • short短型,修饰int、double;
    • long长型,修饰int、double;
    • signed有符号型,修饰int、char;
    • unsigned 无符号型,修饰int、char;

    1.这些限定词经常用来限定int型,在限定int类型时int可以省略;
    2.short和long会改变int型的长度,在不同编译器长度不相同,但是一般short长度不大于int,int长度不大于long;
    3.signed和unsigned不会改变类型长度,仅表示最高位是否为符号位,其中unsigned表示大于等于0的正数;

    取值范围

    为了以后开发中能够方便查找,并正确的使用数据类型,下面是部分数据类型的取值范围:

    • int:-2147483648~2147483647
    • unsigned int:0~4294967295
    • short:-32768~32767
    • unsigned short:0~65535
    • long: -2147483648~2147483647
    • unsigned long:0~4294967295

    存储空间

    下面列出的是常用数据类型占用的存储空间

    数据类型 16位编译器 32位编译器 64位编译器
    char 1byte 1byte 1byte
    int 2byte 4byte 4byte
    float 4byte 4byte 4byte
    double 8byte 8byte 8byte
    short int 2byte 2byte 2byte
    unsigned int 2byte 4byte 4byte
    long 4byte 4byte 8byte
    unsigned long 4byte 4byte 8byte
    long long 8byte 8byte 8byte

    TIPS

    关于这些基本数据类型,平时用的时候有几点需要注意一下:
    1.char类型是最小的数据类型(任意编译器下都是占1Byte),char类型的变量可以赋值某个字符、也可以赋值ASCII值;
    2.可以使用long long来修饰一个整型,但是long long不能修饰double;
    3.不存在short short;
    4.浮点型常量后面加f,编译器认为是float类型,否则是double类型;

    相关文章

      网友评论

      本文标题:OC:基本数据类型

      本文链接:https://www.haomeiwen.com/subject/ogppqttx.html