為什么結果等于3
#include <stdio.h>
int main()
{
? ? int a,b,c,d;
? ? double result;
? ? a = 1;
? ? b = 2;
? ? c = 3;
? ? d = 4;
? ? result = a+? b? +c /d;? ?
? ? printf("%f\n", result);
? ? return 0;
}
#include <stdio.h>
int main()
{
? ? int a,b,c,d;
? ? double result;
? ? a = 1;
? ? b = 2;
? ? c = 3;
? ? d = 4;
? ? result = a+? b? +c /d;? ?
? ? printf("%f\n", result);
? ? return 0;
}
2019-07-19
舉報
2019-07-19
c/d=3/4,c和d都是int型,算出來雖然結果是零點幾,但結果依然為int型,所以等于0。1+2+0=3
2019-07-19
result = a+? b? +c /d;? 賦值符號優先級比較低。先進行運算。整形運算c/d==0,所以右邊等于3。result是雙精度,所以發生隱式轉換,結果為3.000000。