有人能给我解释一下为什么我会得到两个不同的答案吗
#include <stdio.h>
int main()
{
double Vmax = 2.9;
double Vmin = 1.4;
double step = 0.1;
double a =(Vmax-Vmin)/step;
int b = (Vmax-Vmin)/step;
int c = a;
printf("%d %d",b,c); // 14 15, why?
return 0;
}
我希望这两种情况都能得到15分,但似乎我错过了这门语言的一些基本知识.
我不确定这是否相关,但我是在CodeBlock中做测试的.但是,如果我在某个在线编译器(this one for example)中键入相同的代码行,我会得到两个打印变量的答案15.