::资源简介::
一.整型数据
整型数据分int,short,long,unsigned int,unsigned short,unsigned long六种。
首先验证整型数据的字节:
#include<stdio.h>
void main()
{int a;unsigned b;short c;unsigned short d;long e;unsigned long f;
printf("sizeof(a)=%d\n",sizeof(a));
printf("sizeof(b)=%d\n",sizeof(b));
printf("sizeof(c)=%d\n",sizeof(c));
printf("sizeof(d)=%d\n",sizeof(d));
printf("sizeof(e)=%d\n",sizeof(e));
printf("sizeof(f)=%d\n",sizeof(f));
} 运行结果为:
以上为整型数据取值范围的参考值。编程验证
1.验证short int的取值范围
#include<stdio.h>
void main()
{short int a=32767,b=-32768,
e=1,f=-1,g=a+e,h=b+f;
printf("a=%d,b=%d,g=%d,h=%d\n",a,b,g,h);
}运行结果如图所示
b,h的值显然超出范围。因此最小值为g,最大值为a./
2.验证unsigned short int取值范围
::下载地址::
>> 评论