C语言改错问题(有关基本数据类型)
题目: 输入为:12a↙ b↙ 运行结果为:1,2,a,b,123.300000,65535 请改正程序中的错误,使它能得出正确的结果。错误代码:
#include <stdio.h>
main()
{
int b;
unsigned short a = 65535;
short k = a;
char c, d;
int f, g;
b = (1234.0 - 1) / 10;
scanf("%c", &c);
scanf("%c", &d);
scanf("%d", &f);
scanf("%d", &g);
printf("%c,%c,%c,%c,%f,%d", c, d , f, g, b, k);
}
正确代码
#include <stdio.h>
main()
{
double b;
int a = 65535;
char c, d;
int f, g;
b = (1234.0 - 1) / 10;
scanf("%c", &c);
scanf("%c", &d);
scanf("%c\t", &f);
scanf("%c", &g);
printf("%c,%c,%c,%c,%f,%d", c, d , f, g, b, a);
}
问题为什么把a从unsigned short改成int呢?是不是上面的unsigned short a和下面short k=a有冲突?