数据类型
运算符:sizeof(不是一个函数)
sizeof用于获取数据类型或者表达式的长度
如果sizeof后要写一个变量的名字,可以写成如下:1.sizeof(变量); 2.sizeof 变量;
如果写一个类型,必须用第一种
#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 %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;
}
结果:
size of int is 4
size of i is 4
size of char 1
size of j is 1
size of float is 4
size of k is 4
类型限定符
signed:带符号位,只能存放负数
unsigned:不带符号位,只能存放0或正数
#include <stdio.h>
int main()
{
short i;
unsigned short j;
i=-1;
j=-1;
printf("%d\n",i);
printf("%d\n",j);
return 0;
}
结果:
-1
65535
只有i打印出来是-1,而j不行,因为unsinged不能存放负数
浙公网安备 33010602011771号