#include <stdio.h>
int main() {
int f,c;
int lower,upper,step;
lower = 0;
upper = 300;
step = 20;
while (f <= upper) {
c = 5 * (f - 32) / 9;
printf("%d\t%d\n",f,c);
f = f + step;
}
return 0;
}
我忘了写f = lower
,但它也能运行并得到正确答案。我无法发布图片。我认为这是错误的,因为它不能与 Visual C++ 一起运行,但为什么呢?
最佳答案
当您使用时:
int lower,upper,step;
标准不保证变量被初始化为0
,但一些编译器可以。如果我没记错的话,Visual Studio 在调试版本中将函数局部变量初始化为 0
,但在发布版本中没有。
线
while (f <= upper) {
不能保证以可预测的方式运行,因为 f
未在您的程序中显式初始化。
关于c - 为什么此代码在 Dev-C++ 中有效,但在 Visual C++ 中无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27286144/