+ 1
What are the difference between Inline and Macro in C++
2 Respuestas
+ 2
1. The Macros are replaced in process of Preprocessing while inline functions are replaced in compilation process.
2. Inline functions acts as a request to compiler, if it doesn't follow the standards then it acts as normal function and not replaced. Eg: Using recursion with inline Functions.
While Macros are always replaced.
3. Macros are used to replace any code snippet while inline functions are just functions. I have seen many competitive programming codes that have 25-30 macros, out of which 2-5 macros are used for defining for loops. Like: #define F for(int i = 0; i< n; i++)
And then use it like this,
// Original
for(int i= 0; i< n; i++){
...
}
// Using macros
F{
...
}
Just to save time.
* Do not use for production code
0
You can google this question directly for more differences.