编译预处理指令:
以“#”开头是预处理的指令;
用#define 名称 值 ,的形式来定义一个宏;
注意宏的结尾没有分号,因为不是C的语句;
#include<stdio.h>
#define PI 3.1415
int main(int argc, char const* argv[])
{
printf("%f", PI*2);
return 0;
}
其中名字只能是一个东西,但值可以是任何东西;
在C语言的编译器开始编译之前,编译预处理程序(cpp)会把程序中的名字换成值;
如果一个宏的值超过一行需要在未结束的行末加上;\;两个符号。
#include<stdio.h>
#define PI 3.14
#define PI2 6.28
#define FORM "%f\n"
#define PRT printf("%f\n",PI);\
printf("%f\n",PI2)
int main(int argc, char const* argv[])
{
printf(FORM, PI);
PRT;
return 0;
}