What are the difference between Inline and Macro in C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What are the difference between Inline and Macro in C++

7th May 2020, 6:37 AM
Jagatjyoti Mishra
Jagatjyoti Mishra - avatar
2 Answers
+ 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
7th May 2020, 1:49 PM
Arvind Singh Rawat
Arvind Singh Rawat - avatar
0
You can google this question directly for more differences.
7th May 2020, 1:50 PM
Arvind Singh Rawat
Arvind Singh Rawat - avatar