【发布时间】:2020-09-17 18:05:57
【问题描述】:
#include <stdio.h>
int main() {
int a, b;
printf("Enter a number: ");
scanf("%d", &a);
printf("Enter another number: ");
scanf("%d", &b);
int add = a+b;
printf("a + b = %d", add);
return 0;
}
上面是 C 代码,它使用运算符。
我使用 TDM-GCC 4.9.2 64 位 编译器。
每当我运行上述程序时,我都会得到以下输出:
Enter a number:
4
--------------------------------
Process exited after 16.11 seconds with return value 3221225477
Press any key to continue . . .
不允许我输入任何其他号码,也不允许显示任何提示
我想要这个输出:
Enter a number:
4
Enter another number:
2
a + b = 6
--------------------------------
Process exited after <seconds> seconds with return value 0
Press any key to continue . . .
是编译器的问题还是代码的错误?
【问题讨论】:
-
对问题的解释是否正确?还是我应该添加更多信息?
-
尝试使用
-Wall -Wextra构建;对于scanf()需要传递对变量a和b的引用 -
什么是
-Wall -Wextra以及如何使用它构建? -
我整理了所有的错误并编辑了部分代码。它现在运行良好!