macro
Macro substitution is an identifier that is defined with predefine value. In the given program pre-define value work as a substituted value for identifier and when we call(write) identifier in the program its value will be substituted with a pre-define value which is called a macro substitution. it is done with # define value.
syntax
# define identifier ( value )
it has many ways to write a program some of them are here
a. simple macro substitution
b. argument macro substitution
c. nested macro substitution
a. simple macro substitution
Let's be clear from here,
we use the # define 10 functions to define a macro and where ever we use VALUE in the program 10 will be replaced with VALUE. To define a macro we use capital alphabets and we don't need to apply semi-colon(;). They are also used to define symbolic constants and to identify them we use capital alphabets. in macro substitution we can use expression too, we have to use a ( ) bracket to get the correct output. To be more clear let's have a look at the example given below.
Simple macro example
int d = VALUE - 5;
d = 5: // it works as 10-5 = 5
use of expression example
#define AREA (4+1)
#define REAA (5-2)
int x = AREA * REEA
/*
It will follow the operators precedence process to execute.
x = (4+1) * (5-2);
x = 5*3;
x = 12;
*/
Output
12
program
0 Comments