以下语句是否会造成溢出错误?

来源:百度知道 编辑:UC知道 时间:2024/07/07 11:04:24
int a=32767;
char POP='a';
long b=2147483647;
unsigned long f=55555;
unsigned short g=122;
printf("a=%d,byte=%d\n",a,sizeof(int));
printf("POP=%c,byte=%d\n",POP,sizeof(char));
printf("b=%d,byte=%d\n",b,sizeof(long));
printf("f=%d,byte=%d\n",f,sizeof(unsigned long));
printf("g=%d,byte=%d\n",g,sizeof(unsigned short));

结果输出b的值是-1,byte=32767,f的值-9981,byte=0
怎么回事?赋值都没超出范围呀?

%d对应的是int吧
改为printf("b=%ld,byte=%d\n",b,sizeof(long));就好了

在我机子上正常,没出错.我用的VC

自己 去看看LONG 型的定义范围是多少吧