1. #define
Using parameters in define
Note: The preprocessor does not perform calculations, only string substitution
Output
Here's the x+2, replaced and changed to X+2*X+2=14
Here the 100/square (2) is replaced and then becomes 100/2*2=100
++x*++x here the compiler multiplies x by two times
2. #运算符和 # #运算符
From the previous example, you can see that the macro in double quotes is not working, but how to include the macro parameter (#) in the string, this process is called string;
and # like, # #运算符可以用于类函数宏的替换部分
E.
Res:
3. Variable Macros: ... And _ _va_args_ _
Res:
3. #undef
Function: Cancels the definition of a given # define
#define LIMIT 400
#undef LIMIT
4. Conditional compilation
#ifdef/#ifndef #else (On Demand) #endif (must exist)
1#include <stdio.h>2 #defineJust_checking3 #defineLIMIT 44 5 intMain ()6 {7 inti;8 intTotal ;9 Ten for(intI=1; i<=limit;i++) One { Atotal+=2*i*i+1; - #ifdef just_checking -printf"i=%d,running total =%d \ n", total); the #endif - } -printf"Grand total =%d \ n", total); - return 0; +}
5. #line and #error
#line 1000/* Current line number is 1000*/
#line "COOL.C"
6. #pragma--compiling instructions
C Pre-processor