C语言中的数据类型:1、基本类型 ---->整数类型 int
---->浮点数类型 float double
----> 字符类型 char
----> 布尔类型 _Bool
----> 枚举类型 enum
2、构造类型 ----> 数组类型
----> 结构类型
----> 联合类型
3、空类型
C语言中基本数据类型整数类型: *short int *int *long int *long long int (short int<=int<=long int<=long long int)
浮点数类型: *float *double *long double
字符类型: *char
布尔类型: *_Bool ------>值为true 或false
枚举类型: *enum
#includeint main(){ printf("size of short int is %dn" ,sizeof(short)); printf("size of int is %dn" ,sizeof(int)); printf("size of long is %dn" ,sizeof(long)); printf("size of long long is %dn" ,sizeof(long long)); printf("size of char is %dn" ,sizeof(char)); printf("size of _Bool is %dn" ,sizeof(_Bool)); printf("size of float is %dn" ,sizeof(float)); printf("size of double is %dn" ,sizeof(double)); return 0; }
size of short int is 2 size of int is 4 size of long is 4 size of long long is 8 size of char is 1 size of _Bool is 1 size of float is 4 size of double is 8sizeof运算符
*sizeof运算符用于获得数据类型或表达式的长度
-----sizeof(object); //sizeof(对象)
----sizeof(type_name); //sizeof(类型)
----sizeof object; //sizeof 对象
#includeint main(){ int i = 8; char j = 'S'; float k = 3.14; printf("size of int is %dn" ,sizeof(int)); printf("size of i is %dn" ,sizeof(i)); printf("size of char is %dn" ,sizeof(char)); printf("size of j is %dn" ,sizeof(j)); printf("size of float is %dn" ,sizeof(float)); printf("size of k is %dn" ,sizeof(k)); return 0; }
size of int is 4 size of i is 4 size of char is 1 size of j is 1 size of float is 4 size of k is 4signed和unsigned
例如:*(signed) int *unsigned(int)
signed是指带符号的,unsigned是指不带符号的,所有默认的都是signed,如果用unsigned声明了数据类型,那么这个值就不可以带符号,即不可以赋值给它负数。
#includeint main(){ short i; unsigned short j; i = -1; j = -1; printf("i的值为%d",i); printf("j的值为%u",j); return 0; }
i的值为-1 j的值为65535
*存放signed类型的存储单元中,左边第一位表示符号位。如果该位为0,表示该整数是一个正数;如果该位为1,表示该整数是一个负数。
基本数据类型的取值范围
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)