数据类型的赋值?
1种做法:#include <stdio.h>
int main (void)
{
short int a=-30000;
long int b=-1000000000;
unsigned short int c=300000;
unsigned long int d=1000000000;
char e='a';
float f=3.4;
double h=-3.4;
long double i=34.55;
printf("a+c=%u\tX\n",a+c);
printf("b+d=%u\t\tV\n",b+d);
printf("a+e=%d\tV\n",a+e);
printf("e+f=%f\tV\n",e+f);
printf("f+h=%f\tV\n",f+h);
printf("i/f=%f\tV\n",i/f);
printf("e-i=%f\tV\n",e-i);
return 0;
}
2,种做法
#include <stdio.h>
int main (void)
{
int a,b,c,d;
a=-30000,b=-1000000000,c=300000,d=1000000000;
char e;
e='a';
long double f,h,i;
f=3.4,h=-3.4,i=34.55;
printf("a+c=%u\tX\n",a+c);
printf("b+d=%u\t\tV\n",b+d);
printf("a+e=%d\tV\n",a+e);
printf("e+f=%f\tV\n",e+f);
printf("f+h=%f\tV\n",f+h);
printf("i/f=%f\tV\n",i/f);
printf("e-i=%f\tV\n",e-i);
return 0;
}
第一种为什么printf("a+c=%u\tX\n",a+c);计算结果不对。
第二种:在整型数据里有几个变量(short int a=-30000;
long int b=-1000000000;
unsigned short int c=300000;
unsigned long int d=1000000000;)为甚么不能统一定义为int.(int a,b,c,d;
a=-30000,b=-1000000000,c=300000,d=1000000000;)
( float f=3.4;
double h=-3.4;
long double i=34.55;)为甚么不能统一定义为long double.(long double f,h,i;
f=3.4,h=-3.4,i=34.55;)
运行第二代码直接出错。
求大师给个解答,谢谢!