内存中的存储单元是一个线性地址表,按字节进行编址,一个字节等于八个二进制位,也称比特。
sizeof()是C语言提供的专门用于计算指定数据类型字节数的运算符
#include<stdio.h>
int main(void)
{
printf("char %d\n",sizeof(char));
printf("int %d\n",sizeof(int));
printf("short int %d\n",sizeof(short));
printf("long int %d\n",sizeof(long));
printf("long long int %d\n",sizeof(long long));
printf("float %d\n",sizeof(float));
printf("double %d\n",sizeof(double));
printf("lonf double %d\n",sizeof(long double));
return 0;
}
输出
char 1
int 4
short int 2
long int 4
long long int 8
float 4
double 8
lonf double 8