# Connector and # Operator in macro definition

Source: Internet
Author: User

# Connector and # Connector

# The Concatenation symbol is composed of two pound signs. Its function is to connect two substrings (tokens) in the macro definition with parameters to form a new substring. But it cannot be the first or last substring. The so-called token refers to the minimum syntax unit that the compiler can recognize. The specific definition has a detailed explanation in the compilation principle, but it does not matter if you do not know. At the same time, it is worth noting that the # operator replaces the passed parameters as strings. Let's take a look at how they work. This is an example on msdn.

Suppose the program has defined such a macro with parameters:

# Define Paster (n) printf ("token" # N "= % d", Token # N)

At the same time, an integer variable is defined:

Int token9 = 9;

Call this macro in the following way in the main program:

Paster (9 );

During compilation, the above sentence is extended:

Printf ("token" "9" "= % d", token9 );

Note that in this example, the "9" in Paster (9); is regarded as a string and connected with the "token", thus becoming the token9. # N is also replaced by "9.

As you can imagine, the result of running the program above is to print token9 = 9 on the screen.

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.