![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
More sophisticated macros have parameters and take arguments. Consider, for example, the following macro, which you can use when you want to square a number:
Parameter --* *-- Text to be substituted | v v ----- #define square (x) x * x /* First version */
Once you have defined square
as a macro, your C compiler will
replace any appearance of square
, and its argument, before actual
compilation is done. Suppose, for example, that your program exhibits the
following statement:
result = square (length);
Then, your C compiler substitutes the character string,
length
, for the parameter, x
, in the macro definition,
producing the following statement:
result = length * length;