C++/C macro Definition (define) # # # meaning Macro stitching

Source: Internet
Author: User

The Meaning of # # # in C++/C macro definition (define)

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # define.

#是字符串化的意思, the # that appears in the macro definition is a string that is followed by a parameter;

eg

#define STRCPY__ (DST, SRC) strcpy (DST, #src)

Strcpy__ (BUFF,ABC) equivalent to strcpy__ (buff, "abc")

# #是连接符号, connect the parameters together

#define FUN (ARG) my# #arg

Then Fun (ABC)

Equivalent to MYABC

Let's look at a concrete example.

#include <iostream>

using namespace Std;

#define OUTPUT (a) cout<< #A << ":" << (a) <<endl;

int main () {

int a=1,b=2;

OUTPUT (a);

OUTPUT (b);

OUTPUT (A+B);

return 1; }

# # # # # # # # # # # # # # # # # # # # # # We get this result, we print the value of a, B, it's in accordance with the grammatical rules #include <iostream>

using namespace Std;

#define OUTPUT (a) cout<<a<< ":" << (a) <<endl;

int main ()

{

int a=1,b=2;

OUTPUT (a);

OUTPUT (b);

OUTPUT (A+B);

return 1;

}

C++/C macro Definition (define) # # # meaning Macro stitching

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.