1. 程式人生 > >【轉】巨集定義中#和##的使用

【轉】巨集定義中#和##的使用

https://www.cnblogs.com/zhongzhe/p/3892682.html

 

#的功能是將其後面的巨集引數進行字串化操作(Stringfication),簡單說就是在對它所引用的巨集變數通過替換後在其左右各加上一個雙引號

##被稱為連線符(concatenator),用來將兩個Token連線為一個Token,##符是把傳遞過來的引數當成字串進行替代。

 1 #include<cstdio> 
 2 #include<climits>
 3 using namespace std; 
 4 #define STR(s) #s 
 5 #define
CONS(a,b) int(a##e##b) 6 int main() 7 { 8 printf(STR(vck)); // 輸出字串"vck" 9 printf("%d\n", CONS(2,3)); // 2e3 輸出:2000 10 return 0; 11 }