1 #include<stdio.h> 2 3 #define MAX(A,B) A>B?2*A:2*B 4 5 void main() 6 { 7 int a=1,b=2,c=3,d=4,t; 8 t=MAX(a+b,c+d); 9 printf("%d\n",t);10 }
这个程序的运行结果是10而不是14
原因:
宏是字符串替换
t = MAX(a+b,c+d) = a+b>c+d ? 2*a+b : 2*c+d = 2*3+4 = 10