What is the definition of a macro in the C language? __c language

Source: Internet
Author: User
A macro definition is one of the three preprocessing functions provided by C, which includes the following three types of preprocessing: macro definition, file inclusion, conditional compilation

A macro definition is also called a macro substitution, a macro substitution, or a macro.
Format: #define Identifier string
The identifier is called the symbolic constant, also known as the "macro name."
Preprocessing (precompiled) work is also called macro expansion: Replace the macro name with a string.
The key to mastering the concept of "macro" is "change". Everything to change for the premise, do anything before you want to change, accurate understanding before you must "change."
That is, before you make a specific analysis of the meaning and function of the relevant command or statement, you must change it:
Example: #define PI 3.1415926
Replace the pi that appears in the program with 3.1415926.
Description
(1) Macro name generally used in uppercase
(2) The use of macros can improve the universality and readability of the program, reduce the inconsistency, reduce the input error and facilitate modification. For example: array size common macro definition
(3) Preprocessing is the processing before compiling, and one of the tasks of compiling work is grammar check, preprocessing does not do grammar check.
(4) No semicolon at the end of the macro definition;
(5) The macro definition is written outside the curly braces of the function, and the scope is the program that follows, usually at the very beginning of the file.
(6) The scope of the macro definition can be terminated with the #undef command
(7) Macro definitions cannot be nested
(8) The string "" will never contain macros
(9) Macro definition does not allocate memory, variable definition allocates memory.
(10) The macro definition does not have a type problem, and its arguments are not typed.
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.