Use of # # in C + + (GO)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.