Transferred from: http://blog.sina.com.cn/s/blog_4cf015f201009o1d.html
The first case is a stringizing Operator (#), called a string.
#define Stringer (x) printf (#x "\ n") int main () { stringer (in quotes in the printf function call\n); Stringer ("in quotes when printed to the screen" \ n); Stringer ("this: \" Prints an escaped double quote "); }
Such a definition will be converted to the following code when it is processed:
int main () { printf ("in quotes in the printf function call\n" \ n "); printf ("\" in quotes-printed to the screen\ "\ n" "\ n"); printf ("\" this: \\\ "prints an escaped double quote\" "\ n"); }
The results of the program run as follows:
In quotes in the printf function call ' in quotes when printed to the screen ' this: \ ' Prints an escaped double quotation m Ark
The second situation as charizing Operator (#@), is called the word Fu Hua.
Example:
#define MAKECHAR (x) #@x
Causes the statement
A = Makechar (b);
This statement will be extended to
A = ' B '; Note that single quote characters cannot be used with such a character.
The third situation as token-pasting Opertor (# #), called the connector, is probably the meaning.
Example: #define PASTER (N) printf ("token" #n "=%d", token# #n) int token9 = 9;
If a number is called as a parameter to this macro,
Paster (9);
The macro is expanded to
printf ("token" "9" "=%d", token9);
Then it becomes the statement: printf ("Token9 =%d", token9);
Use of # # in C + + (GO)