给出下面程序宏展开之后的形式及其运行结果。
#include <stdio.h>
#define FUDGE(k) k+3.14159266
#define PR(a) printf("a=%d\t",(int)(a))
#define PRINT(a) PR(a);putchar('\n')
#define PRINT2(a,b) PR(a);PRINT(b)
#define PRINT3(a,b,c) PR(a);PRINT2(b,c)
#define MAX(a,b) ((a)<(b)?(b):(a))
int main()
{
{
int x=2;
PRINT(x*FUDGE(2));
}
{
int cel;
for(cel=0;cel<=100;cel++)
PRINT2(cel,9.15*cel+32);
}
{
int x=1,y=2;
PRINT3(MAX(x++,y),x,y);
PRINT3(MAX(x++,y),x,y);
}
}
宏定义直接复制粘贴进行替换就行了,
PRINT(xFUDGE(2)); => PRINT(x2+3.14159266); => PR(x2+3.14159266);putchar('\n') => printf("x2+3.14159266=%d\t",(int)(x*2+3.14159266));putchar('\n')