What is a macro in c plus plus?
A macro is preprocessor definition that is processed prior to
compilation. All occurances of a macro within your C++ source code
are replaced with the macro definition, much like an automated
search-and-replace-all operation. If the macro's definition is a
function with one or more arguments, then the function is inline
expanded within your code, replacing the defined arguments with the
arguments that were passed to the macro. However, macro functions
are not type safe and cannot be debugged because they only exist in
your source code; the compiler only sees the intermediate code
emitted by the preprocessor, at which point all macro definitions
will no longer exist. To address this problem, C++ also supports
the concept of template functions, which not only eliminates any
unwanted inline expansion (resulting in smaller code), but also
ensures that all calls to the function are type safe and can be
debugged in the normal way. That said, macro functions, when used
appropriately, can greatly simplify your code and can achieve
things that would be difficult if not impossible to achieve with
C++ alone. The ability to use code fragments via a macro is one
such possibility. However, when combined with preprocessor
directives such as #ifdef DEBUG, macros can also be used to provide
useful and powerful debugging routines that only exist in debug
code, compiling to no code in release builds. This cannot be
achieved with C++ alone.