Sum of two numbers using a simple macro:
#include <iostream>
#define sum(a, b) a + b
int main()
{
int a = 3;
int b = 2;
std::cout<<sum(a,b);
return 0;
}
The first and main reason is portability in different architectures or compilers because all the preprocessor directives are processed before the start of compilation and get’s replaces by corresponding code.
On the second hand a preprocessor directive improves readability of the program making it easy to maintain and can scale verry quickly.
You can read more about C/C++ preprocessors here.