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
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