#defind Pi 3.14159
或
#ifndef __THIS_FILE__
#define __THIS_FILE__ // 用於防止重複包含文件
…… ……
#endif
___________________________
②條件宏替換
#define p(x) printf(x)
…… ……
p("hello!");
→ hello!
___________________________
③字符宏替換(#@)
#define pchar(x) printf("%c\n", #@x)
…… ……
pchar(a);
→ a
___________________________
④字串宏替換(#)
#define pstring(x) printf("%s\n", #x)
…… ……
pstring(hello!);
→ hello!
___________________________
⑤連接宏替換(##)
#define p( n ) printf( "symbol" #n " = %d", symbol##n )
…… ……
int symbol9 = 9;
p( 9 );
→ symbol9=9
ANSI C標準中有幾個標準預定義宏:__FILE__ __DATE__ __TIME___ __LINE__ 等
__LINE__:在源代碼中插入當前源代碼行號;
__FILE__:在源文件中插入當前源文件名;
__DATE__:在源文件中插入當前的編譯日期
__TIME__:在源文件中插入當前編譯時間;
__STDC__:當要求程序嚴格遵循ANSI C標準時該標識被賦值爲1;
__cplusplus:當編寫C++程序時該標識符被定義。