条件编译
在调试程序阶段,这样处理便于观察
#include <stdio.h>
#define DEBUG //在运行程序时使之成为注释行
int main( )
{
int x=1,y=2;
#ifdef DEBUG
printf("x=%d, y=%d\n", x, y);
#endif
printf("x*y=%d\n", x*y);
return 0;
}
结束调试,只需要很少改变(尤其是调试中需要很多观察点时)
#include <stdio.h>
#define DEBUG //在运行程序时使之成为注释行
int main( )
{
int x=1,y=2;
#ifdef DEBUG
printf("x=%d, y=%d\n", x, y);
#endif
printf("x*y=%d\n", x*y);
return 0;
}
条件编译的常用形式之二
#include <stdio.h>
#define R 1
int main(void)
{
float c,r,s;
printf ("input a number: ");
scanf("%f",&c);
#if R
r=3.14159*c*c;
printf("area of round is: %f\n",r);
#else
s=c*c;
printf("area of square is: %f\n",s);
#endif
return 0;
}