Pre-processing macros in C + +

Source: Internet
Author: User
Pre-processing macros in C + +

An example of a preprocessing macro:

# define PRINT (Str,var) cout<<str "=" <<VAR<<endl;

The arguments in parentheses following the macro name are replaced by all code that follows the closing parenthesis. Whenever the macro is called, the preprocessor removes the name print and replaces the code, so the compiler does not report any error messages when using the macro name, and it does not do any type checking on the parameters.

Another example:

# define P (EX) cout<< #EX << ":" <<EX<<endl;

The "#" is called the preprocessing feature of the string, and its function is to get any expression and convert it to a character array.

C + + function address

Once the function is compiled and loaded into the computer, it consumes a chunk of memory. This memory has an address, so the function also has an address. Once a function pointer is defined, it must be given a function address before it is used. As the address of an array arr[10] is generated by an array name (arr) without square brackets, the address of the function func () is also generated by the function name (func) without the parameter list. You can also use the more obvious syntax: &func (). In order to invoke this function, the pointer should be referenced indirectly in the same way as the declaration.

Pre-processing macros in C + +

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.