#, # Usage in C

Source: Internet
Author: User

1 .#
If you want to include a macro parameter in a string, ansi c allows this. In the macro replacement section of the class function, # symbol is used as a preprocessing operator, which can convert the language symbol to the string. For example, if X is a macro parameter, # X can convert the parameter name into a corresponding string. This process is called stringizing ).

 
# Include <stdio. h> # define print (x) printf ("the value of print (" # X ") is % d \ n", x) int main () {print (5 + 20); Return 0 ;}

 

2 .##

# Operators can be used to replace class function macros. In addition, ## can be used to replace Class Object macros. This operator combines two language symbols into a single language symbol.

# Include <stdio. h> # define xname (n) x # N # define pxn (n) printf ("X" # N "= % d \ n", X # N) int main (void) {// int xname (1) = 12; // int X1 = 12; // pxn (1 ); // printf ("X1 = % d \ n", X1); int I = 0; for (I = 0; I <10; I ++) {int xname (I) = I; pxn (I);} return 0 ;}

 

 

 

 

 

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.