Got it! This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
The C language (and C++ language) has a macro facility for code text replacement (i.e., a string rewriting system as part of the language).
Here are two code examples. Both output some header text and the result of a computation.
The first uses plain C code.
The second uses the C macro feature.
3. C multi-line macros
Note that C macros require parentheses both in definition and in usage. If not, then it is just a plain define directive.
A multi line C macro has a backslash at the end of the line and continues until a line without a backslash at the end of the line is found.
A usual convention is that macro names and parameters are in all uppercase.
Here is the C code.
Here is the output of the C code.
Now, let us use a C macro for the print (just as an example).
Here is the C code.
Here is the output of the C code.
4. Summary
The C (and C++) macro feature provides a way to substitute repeated text, or repeated text with some parameter supplied changes, to replicate almost the same code in many places.
This can be useful when the code must run very fast and calls to functions would be time-consuming or the parameter lists needed would be inconvenient.
For more information, try a search for "c preprocessor multi line macro" or "c++ preprocessor multi line macro".