+ 2
What are Macros in C?
2 Answers
+ 4
Macros in C are string replacements commonly used to define constants. ... Basically macros are one of the Preprocessor directives available in C. Macro substitution is a process where an identifier in a program is replaced by a predefined string.
+ 1
A macro is a segment of code which is replaced by the value of macro. Macro is defined by #define directive. There are two types of macros:
Object-like Macros
Function-like Macros
Object-like Macros
The object-like macro is an identifier that is replaced by value. It is widely used to represent numeric constants. For example:
#define PI 3.14
Here, PI is the macro name which will be replaced by the value 3.14.
Function-like Macros
The function-like macro looks like function call. For example:
#define MIN(a,b) ((a)<(b)?(a):(b))