本次课的内容是 1)宏定义 1、预处理命令 2)文件包含 3)条件编译 、指针和指针变量的概念 3、指针变量的使用
本次课的内容是: 1、预处理命令 2、指针和指针变量的概念 3、指针变量的使用 1)宏定义 2)文件包含 3)条件编译
第9章预处理命令 ★作用:对源程序编译之前做一些处理.生成扩展名 为的C源程序 ★种类 今宏定义 define 今文件包含# include ◆条件编译#-#else-#end等 ★格式 #”开头 占单独书写行 今语句尾不加分号
第9章 预处理命令 作用:对源程序编译之前做一些处理,生成扩展名 为的C源程序 种类 ❖宏定义 #define ❖文件包含 #include ❖条件编译 #if--#else--#endif 等 格式: ❖“#”开头 ❖占单独书写行 ❖语句尾不加分号
89.1宏定义 ★不带参数宏定义 ◆一般形式:# efine宏名字符串 令功能用指定标识(宏名)代替字符串 如# define Yes1 define no 0 # define F3.1415926 tdefine oUt printf("Hello, World)
§9.1 宏定义 不带参数宏定义 ❖一般形式: #define 宏名 字符串 ❖功能:用指定标识符(宏名)代替字符串 如 #define YES 1 #define NO 0 #define PI 3.1415926 #define OUT printf(“Hello,World”);
令定义位置任意(一般在函数外面 ◆作用域从定义命令到文件结束 # undef可终止宏名作用域 格式:# undef宏名 例# define YEs1 maino YES原作用域 indef yes define YEs 0 maxo YES新作用域
❖定义位置:任意(一般在函数外面) ❖作用域:从定义命令到文件结束 ❖#undef可终止宏名作用域 格式: #undef 宏名 例 #define YES 1 main() { …….. } #undef YES #define YES 0 max() {…….. } YES原作用域 YES新作用域
◇宏展开:预编译时,用字符串替换宏名 不作语法检查 if (X==YES) printf("correct!n) else if ( X==No printf("error! n) 展开后:f(X=1) printf("correct!n) else if (x==0) printf("error!n 爷引号中的內与宏名祁同也不萓抉 例# define p3.14159 printf(2*P=%f\n,, PI*2) 宏展开:prnt(“2*P=%hn”,3.14159*2);
❖宏展开:预编译时,用字符串替换宏名-- -不作语法检查 ❖引号中的内容与宏名相同也不置换 例 #define PI 3.14159 printf(“2*PI=%f\n”,PI*2); 宏展开:printf(“2*PI=%f\n”,3.14159*2); 如 if(x==YES) printf(“correct!\n”); else if (x==NO) printf(“error!\n”); 展开后: if(x==1) printf(“correct!\n”); else if (x==0) printf(“error!\n”);