数据类型:
char
字符数据类型 例:“A”,
#include <stdio.h>
int main()
{
char a='d'; //申请一块内存 内容为单引号
printf("%c\n",a); //%c是打印字符格式的数据
return 0;
}
short
短整型
int
整型 例 1 5 60 等整数数字
#include <stdio.h>
int main()
{
int a=9; //申请一块内存 int整型
printf("%d\n",a); //%d是打印十进制数据
return 0;
}
long
长整型
long long
更长的整型
float
单精度浮点数 例:1.5 3.9 0.1
double
双精度浮点数 后面显示六位数字
占用比特位数:
单位的换算:
8bit(比特位)=1byte(字节)
1024byte=1kb
1024kb=1mb
1024mb=1gb
1024gb=1tb
1024tb=1pb
数据类型的占用比特位数代码:
#include <stdio.h>
int main()
{
printf("%d\n",sizeof(char));
printf("%d\n",sizeof(short));
printf("%d\n",sizeof(int));
printf("%d\n",sizeof(long));
printf("%d\n",sizeof(float));
printf("%d\n",sizeof(double));
}
对应的结果:
1
2
4
4
4
8
Press any key to continue
所以我们可以知道char(字符数据类型)占用1字节
short(短整型)占用2字节
int(整型)占用4字节
long(长整型)占用4字节
float(单精度浮点数)占用4字节
double(双精度浮点数)占用8字节