以下代码的输出 - c 中的宏
Output of the following code- macros in c
对于以下代码,我得到的输出是- Geeks。
#include <stdio.h>
#define ISEQUAL(X, Y) X == Y
int main()
{
#if ISEQUAL(X, 0)
printf("Geeks");
#else
printf("Quiz");
#endif
return 0;
}
解释这样输出的原因。
条件宏 #if ISEQUAL(X, 0)
扩展为 #if X == 0
。预处理结束后,所有未定义的宏都初始化为默认值0
。由于宏X
还没有定义,所以用0
初始化。因此,"Geeks" 被打印出来。
对于以下代码,我得到的输出是- Geeks。
#include <stdio.h>
#define ISEQUAL(X, Y) X == Y
int main()
{
#if ISEQUAL(X, 0)
printf("Geeks");
#else
printf("Quiz");
#endif
return 0;
}
解释这样输出的原因。
条件宏 #if ISEQUAL(X, 0)
扩展为 #if X == 0
。预处理结束后,所有未定义的宏都初始化为默认值0
。由于宏X
还没有定义,所以用0
初始化。因此,"Geeks" 被打印出来。