##的使用举例:
#include <stdio.h>
#define A(J,K) &(J##K)
int main(){
int JK = 1024;
printf("%d\n",*(A(J,K)));
/**
* 相当于 ==> printf("%d\n",*(&JK));
* 注意A的宏定义中对(J##K)进行了取地址操作
*
* */
printf("%p",&JK);
return 0;
}
打印结果:
JK = 1024
addr of JK = 0061FF1C
## 使用举例进阶:
#include <stdio.h>
typedef struct User{
int * age;
}User;
int user_age = 1024;
#define UserInit(obj){\
& obj ## _age \
\
}
int main(){
User user = UserInit(user);
printf("age = %d",*user.age);
return 0;
}
打印结果:
age = 1024