#include
#define FUNC(X,Y) (1/(X)+1/(Y))
int main(void)
{
double x=FUNC(2,2);
printf("%lf\n",x);
return 0;
}
在VS2013中編譯沒有錯誤,但是輸出結果是0.000000,為什麼?是#define用錯了嗎?
In C the divide between int also return int
so 1/2=0
so 1/2 + 1/2 = 0
solution
#define func(x,y) (1.0/(x)+1.0/(y))