- #include <stdio.h>
- #define n 6 //宏定义
- #define m(h,i) h*i //宏定义
- #define o(h) h*h //宏定义
- #define p(h) (h)*(h) //宏定义
- int main()
- {
- printf("n=%d\n",n);
- printf("n+100=%d\n",n+100);
- printf("n\n"); //用双引号括起来不做宏替换
- #undef n //结束作用域被替换的内容
- {
- int n=99;
- printf("n=%d\n",n);
- }
- int a=m(2,3); //等价于int a=2*3;
- printf("a=%d\n",a);
- int b=o(5); //等价于int b=5*5;
- printf("b=%d\n",b);
- int c=o(5+6); //等价于int c=5+5*6+6;
- printf("c=%d\n",c);
- int d=p(5+6); //等价于int d=(5+6)*(5+6)
- printf("d=%d\n",d);
- return 0;
- }
复制代码
|
|