c语言中 int类型等

来源:互联网 发布:动迁三块砖算法 编辑:程序博客网 时间:2024/06/10 21:59
   ANSIC标准里是没有规定占多少字节的,准确地说与你的计算机CPU位数和操作系统位数无关,类型大小是由编译器厂商compiled时定义的,具体你可以在你编译器sizeof看一下。

那么一般是多少字节的呢?
          int long float double char
16位:2   2       2     4         1,
32位:4   4       4     8         1

可用以下例子测试:
#include"stdio.h"
int main()
{
  printf("the size of int is %d\n",sizeof(int));
  printf("the size of long is %d\n",sizeof(long));
  printf("the size of float is %d\n",sizeof(float));
  printf("the size of double is %d\n",sizeof(double));

}
用gcc -o test test.c
结果:#include"stdio.h"
the size of int is 4
the size of long  is 4
the size of float is 4
the size of double is 8