数据类型
char-字符数据类型
short-短整型
int-整型
long-长整型
long long-更长的整型
float-单精度浮点型 浮点数=小数
double-双精度浮点型
1.各数据类型所占空间
#include<stdio.h> int main() { printf("%dn",sizeof(char)); //1 sizeof...的大小(字节) printf("%dn",sizeof(short)); //2 printf("%dn",sizeof(int)); //4 printf("%dn",sizeof(long)); //4/8 printf("%dn",sizeof(long long)); //8 printf("%dn",sizeof(float)); //4 printf("%dn",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("%cn",ch); //%c-打印字符格式的数据 6 return 0; 7 }
②
1 #include<stdio.h> 2 int main() 3 { 4 int age = 20; //向内存申请四个字节用来存放20 5 printf("%dn",age); //%d-打印整型十进制数据 6 return 0; 7 }
③
1 #include<stdio.h> 2 int main() 3 { 4 float f = 5.0; //向内存申请4个字节存放小数 5 printf("%fn",f); //%f-打印浮点数 6 return 0; 7 }
④
1 #include<stdio.h> 2 int main() 3 { 4 double d = 3.14; 5 printf("%lfn",d); //%lf-打印双精度浮点数 6 return 0; 7 }
内容来源于网络如有侵权请私信删除
文章来源: 博客园
- 还没有人评论,欢迎说说您的想法!