一、数据类型
二、数据长度
1、sizeof()
sizeof()运算符用于获得数据类型或表达式的长度。
sizeof(object);//sizeof(对象)
sizeof(type_name);//sizeof(类型)
sizeof object ;//sizeof 对象 ;
int = 4(int类型的长度取决于环境)
short i = 2
long = 4
char = 1
float = 4
double = 8
long double = 8
例如:
#include "stdio.h"
int main()
{
int i;
char j;
float k;
i = 123;
j = 'C';
k = 3.14;
printf("size of int is %d\n",sizeof(int));
printf("size of i is %d\n",sizeof(i));
printf("size of char is %d\n",sizeof(char));
printf("size of j is %d\n",sizeof(j));
printf("size of float is %d\n",sizeof(float));
printf("size of k is %d\n",sizeof(k));
return 0;
}
#include "stdio.h"
int main()
{
printf("int = %d\n",sizeof(int));
printf("short i = %d\n",sizeof(short int));
printf("long = %d\n",sizeof(long));
printf("long long = %d\n",sizeof(long long));
printf("char = %d\n",sizeof(char));
printf("float = %d\n",sizeof(float));
printf("double = %d\n",sizeof(double));
printf("long double = %d\n",sizeof(long double));
return 0;
}
三、正负数据的储存
1、unsigned
无符号类型,首位不用0或者是1表示正负,32位的整形可以有32个比特为表示值。
2、signed
有符号类型,首位0正值,1表示负值,32位的整形只有有31个比特为表示值。
注意
计算机用补码的方式存放值。