一、#define f(x) x*x
#include<stdio.h>
#define f(x) x*x
int main()
{
int a=6,b=2,c;
c=f(a)/f(b);
printf("f(a)=%d\n",f(a));//6*6
printf("f(b)=%d\n",f(b));//2*2
printf("f(b+1)=%d\n",f(b+1));//2+1*2+1;
printf("f(b+2)=%d\n",f(b+2));//2+2*2+2
printf("f(b+3)=%d\n",f(b+3));//2+3*2+3
printf("f(a)/f(b)=%d\n",c);//36/(2+1)*(2+1)=36;
return 0;
}
1.按照我们定义f(x)函数的初衷,我们希望f(b+1)=3*3=9,但现实是f(b+1)=5;
f(b+1)=5的运算逻辑则是 2+1*2+1=5
f(b+2)=8的运算逻辑则是 2+2*2+2=8
f(b+3)=11的运算逻辑则是 2+3*2+3=11
即 f(b+n)=b+n*b+b;
2.同样按照我们定义f(x)的函数的初衷,我们希望f(a)/f(b)=36/9=4,但现实是f(a)/f(b)=36;
f(a)/f(b)=36,背后的逻辑则是 36/(2+1)*(2+1)=36;相等于等于其本身
3.我们如果想修正这个函数为我们定义f(x)的初衷,就应该在整个函数外面加个括号,例如g(x)
#include<stdio.h>
#define f(x) x*x
#define g(x) ((x)*(x))//修正
int main()
{
int a=6,b=2,c;
c=f(a)/f(b);
printf("f(a)=%d\n",f(a));//6*6
printf("f(b)=%d\n",f(b));//2*2
printf("f(b+1)=%d\n",f(b+1));//2+1*2+1;
printf("f(b+2)=%d\n",f(b+2));//2+2*2+2
printf("f(b+3)=%d\n",f(b+3));//2+3*2+3
printf("f(a)/f(b)=%d\n",c);//36/(2+1)*(2+1)=36;
printf("\n");
printf("g(a)=%d\n",g(a));
printf("g(b)=%d\n",g(b));
printf("g(b+1)=%d\n",g(b+1));
printf("g(a)/g(b)=%d\n",g(a)/g(b));
return 0;
}