数据类型

1、16位编译器

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

2、32位编译器

char :1个字节
char*: 4个字节    
short    int : 2个字节
int: 4个字节
unsigned int : 4个字节
float: 4个字节
double: 8个字节
long: 4个字节
long long: 8个字节
unsigned long: 4个字节

拓展资料:

整型数据的一般分类如下:

1、基本型:类型说明符为int,在内存中占2个字节。

2、短整型:类型说明符为short int或short。所占字节和取值范围均与基本型相同。

3、长整型:类型说明符为long int或long,在内存中占4个字节。

4、无符号型:类型说明符为unsigned。无符号型又可与上述三种类型匹配而构成:

1)无符号基本型:类型说明符为unsigned int或unsigned。

2)无符号短整型:类型说明符为unsigned short。

3)无符号长整型:类型说明符为unsigned long。

    深入理解计算机系统这本书,上面提到了在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。

posted @ 2020-03-24 18:39  北极星!  阅读(237)  评论(0编辑  收藏  举报