c語言 宏定義 去除宏定義
To check whether a Macro is defined or not in C language – we use #ifdef preprocessor directive, it is used to check Macros only.
要檢查是否用C語言定義了宏 -我們使用#ifdef預處理程序指令,它僅用于檢查宏。
Syntax:
句法:
#ifdef MACRO_NAME
//body
#endif
If MACRO_NAME is defined, then the compiler will compile //body (a set of statements written within the #ifdef ... #endif block).
如果定義了MACRO_NAME ,則編譯器將編譯// body (在#ifdef ... #endif塊中編寫的一組語句)。
Example:
例:
#include <stdio.h>
#define NUM 100
int main()
{
//checking a defined Macro
#ifdef NUM
printf("Macro NUM is defined, and its value is %d\n",NUM);
#else
printf("Macro NUM is not defined\n");
#endif
//checking an undefined Macro
#ifdef MAX
printf("Macro MAX is defined, and its value is %d\n",MAX);
#else
printf("Macro MAX is not defined\n");
#endif
return 0;
}
Output
輸出量
Macro NUM is defined, and its value is 100Macro MAX is not defined
翻譯自: https://www.includehelp.com/c-programs/check-whether-a-macro-is-defined-or-not-in-c.aspx
c語言 宏定義 去除宏定義