问题形容1
将默认为双精度的实型常量赋值给单精度变量。
语句编写:
#include<stdio.h>#define pl 3.14int main(){ float r,area; r=1.5; area=pl*r*r; printf("area=%f\n",area); return 0;}
编译正告️
werning C4244:"=’:co onversion from 'double / to "float
但不影响程序运行
解决办法:
如果将float批改为double,将%f批改为%lf后,就没有正告了。
运行后果:
问题形容2
两个定义的时候,同时赋初值。
语句编写:
#include<stdio.h>int main(){ int x=y=2,z; z=x+y; printf("x+y=%d\n",z); return 0;}
编译谬误erlor c2065: 'y' : undeclared identifier
解决办法:
变量x和y独自定义独自赋初值,将int x=y=2,z批改为int x=2,y=2,z;
运行后果:
问题形容3:
将带双引号的字符串赋值给了字符变量
语句编写:
#include<stdio.h>int main(){ char ch; ch="A"; printf("%c的ASCll的值为:%d\n",ch,ch); return 0;}
编译正告️
warning c4847: "=" : "char " diff Fers in levels of indirection from "char [2]
解决办法:
将字符串"A"批改为字符'A'。
运行后果:
问题形容4:
实型数据参加了%(求余)运算
语句编写:
#include<stdio.h>int main(){ printf("%d\n",3%2.0); return 0;}
编译谬误:error C2297: '%' : illegal, right operand has type "const double "
解决办法:
只有整数能力加入%(求余)运算,将2.0批改为2。
运行后果:
乘法运算问题
问题形容5:
两个变量进行乘法运算时,遗记书写乘号"*"。
语句编写:
#include<stdio.h>int main(){ double l=2,w=3,s; s=lw; printf("s=%lf\n",s); return 0;}
编译谬误 error c2065: 'lw’: undeclared identifler
解决办法:
乘法的符号不能省略,将s=lw;批改为s=l*w;
运行后果: