早教吧 育儿知识 作业答案 考试题库 百科 知识分享

#includemain(){inta=0x7fffffff,b=025;floatf1=123.456,f2=2.0;charc1,c2;cl='a';c2='b';printf("a=%d,b=%d\n",a,b);printf("c1=%c,c2=%c\n",c1,c2);printf("fi=%e,f2=%f\n",f1,f2);a=f1;b=f2;printf("a=%d,b=%d\n",a,b);}D:\课件\VC6\MyProjects\d\d.c(5):warn

题目详情
#include
main()
{
int a=0x7fffffff,b=025;
float f1=123.456,f2=2.0;
char c1,c2;
cl='a';
c2='b';
printf("a=%d,b=%d\n",a,b);
printf("c1=%c,c2=%c\n",c1,c2);
printf("fi=%e,f2=%f\n",f1,f2);
a=f1;
b=f2;
printf("a=%d,b=%d\n",a,b);
}
D:\课件\VC6\MyProjects\d\d.c(5) :warning C4305:'initializing' :truncation from 'const double ' to 'float '
D:\课件\VC6\MyProjects\d\d.c(7) :error C2065:'cl' :undeclared identifier
D:\课件\VC6\MyProjects\d\d.c(12) :warning C4244:'=' :conversion from 'float ' to 'int ',possible loss of data
D:\课件\VC6\MyProjects\d\d.c(13) :warning C4244:'=' :conversion from 'float ' to 'int ',possible loss of data
执行 cl.exe 时出错.
哪里错了请大神指教呀
▼优质解答
答案和解析
错误是因为,你定义的char c1,你在下面赋值写的cl,所以error错误是 没有定义cl.至于你发的warning是警告,意思是float转int可能会损失精度.