数据类型spa
char-字符数据类型code
short-短整型blog
int-整型内存
long-长整型it
long long-更长的整型io
float-单精度浮点型 浮点数=小数class
double-双精度浮点型数据类型
1.各数据类型所占空间float
#include<stdio.h> int main() { printf("%d\n",sizeof(char)); //1 sizeof...的大小(字节) printf("%d\n",sizeof(short)); //2 printf("%d\n",sizeof(int)); //4 printf("%d\n",sizeof(long)); //4/8 printf("%d\n",sizeof(long long)); //8 printf("%d\n",sizeof(float)); //4 printf("%d\n",sizeof(double)); //8 return 0; }
标准C语言规定sizeof(long)>=sizeof(int),因此long能够为4个字节也能够为8个字节数据
每一个数据类型有2n个数,取值范围为0~2n-1
注:计算机单位换算
1byte(比特位)=8bit(字节)
1kb=1024bit
1mb=1024kb
1gb=1024mb
1tb=1024gb
1pb=1024tb
2.数据类型的用法
①
1 #iniclude<stdio.h> 2 int main() 3 { 4 char ch = 'A'; //向内存申请一个字节用来存放A 5 printf("%c\n",ch); //%c-打印字符格式的数据 6 return 0; 7 }
②
1 #include<stdio.h> 2 int main() 3 { 4 int age = 20; //向内存申请四个字节用来存放20 5 printf("%d\n",age); //%d-打印整型十进制数据 6 return 0; 7 }
③
1 #include<stdio.h> 2 int main() 3 { 4 float f = 5.0; //向内存申请4个字节存放小数 5 printf("%f\n",f); //%f-打印浮点数 6 return 0; 7 }
④
1 #include<stdio.h> 2 int main() 3 { 4 double d = 3.14; 5 printf("%lf\n",d); //%lf-打印双精度浮点数 6 return 0; 7 }