Moh*_*wez 1 c variables c-preprocessor
#if !defined(STDIO_H) && !defined(STDLIB_H)
#include<stdio.h>
#include<stdlib.h>
#endif
#if !defined(LIMITS_H)
#include<limits.h>
#endif
#if !defined(MATH_H)
#define pow(a,b) {\
int i=1,p=1;\
while(i<=b)\
{\
p=p*a;\
i++;\
}\
printf("%d\n",p);\
}
#define join(a,b) a##b
#endif
int main()
{
int a,b;
printf("Enter a b : ");
scanf("%d %d",&a,&b);
pow(a,b);
printf("%d\n",join(a,b));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
错误是一致的,printf("%d",join(a,b));但如果我用 56 和 34 之类的常量替换 a & b,它就可以完美运行。
预处理器在编译时运行。所以'##' 运算符在编译时被评估。您不能将它与在运行时确定的值一起使用。
这里发生的事情a##b是简单地转换为ab,因此出现错误ab undefined。