Macros
Example:
#define PI 3.14
#define PRNT(a, b))
printf("value1 = %d\n", a);
printf("value2 = %d\n", b);
int main() {
int x = 2;
int y = 3;
PRNT(x, y);
return 0;
}Macros vs functions
Alternatives
Creating macros
There are 2 ways of defining macros:
1. Symbolic constants (constants represented as symbols).
2. Function macros (operations defined as symbols).
Symbolic constants
Example:
Defines a macro and some replacement text. after definition the macro can be used as follows:
Example:
Function macros
Example:
Using:
Example:
Output:
Macros with arguments
Example:
Standard C pre-defined macros
Last updated