當我運行此代碼時,D的輸出作爲值C出現。是因爲我要求一個浮點數,它只是在內存中使用最近的浮點數?當我不匹配格式說明符時,爲什麼我會收到另一個變量的值?
#include <stdio.h>
int main()
{
int a=3/2;
printf("The value of 3/2 is : %d\n", a);
float b=3.0/2;
printf("The value of 3/2 is : %f\n", b);
float c=7.0/2; <-------
printf("The value of 3/2 is : %f\n", c);
int d=3.0/2;
printf("The value of 3/2 is : %f\n", d); <-------
return 0;
}
The value of 3/2 is : 1
The value of 3/2 is : 1.500000
The value of 3/2 is : 3.500000
The value of 3/2 is : 3.500000
未定義的行爲未定義。 –
我想你是在x64平臺上 –
@ M.M:你的意思是因爲在64位浮點數值通過SSE寄存器傳入,那麼'3.5'仍然是該寄存器中的值? –