Briefly explain macro function
Briefly explain macro function
Macro function
Macros are generally used in C/C++ programming language. They refer to the name given to a value (or a segment of code). Whenever that name is used in a program, it will be replaced by the value of that macro. It is usually a one-line statement that appears at the beginning of the program.
Macros are defined in the program using the #define preprocessor directive which precedes by valid identifier name and value as a numeric or string that must be substituted by the preprocessor whenever that macro encounters in the program.
For example:
#define PI 3.14
where PI is the name of the macro which will be replaced by the value 3.14 in the program.
The macros that are accepting arguments and return values are called function-like macros.
For example:
The following macro is defined with one argument. Whenever areaOfCircle(argument) occurs in a program, it will be replaced by (3.14*(argument)*(argument)).
#define areaOfCircle(radius) (3.14*(radius)*(radius))
Step by step
Solved in 2 steps