Both Inline function and Macro works the same in almost all scenarios there are lot of key difference between them.
Before we get into those topics what is this inline and macro actually?
They are kind of like functions but instead of control passing which happens in functions these will replace the actual line of call by the function body..
for example
--------------------------------------------------------------------------------------------------------------------------
MACRO:
#define MAX(x,y) x>y?x:y
would give the largest among 2 parameters on the call of MAX(a,b)
If we are to write
int j=MAX(2,3);
The preprocessor would replace the statement as
int j=3;
before execution
INLINE:
inline int add(int a, int b)
Before we get into those topics what is this inline and macro actually?
They are kind of like functions but instead of control passing which happens in functions these will replace the actual line of call by the function body..
for example
--------------------------------------------------------------------------------------------------------------------------
MACRO:
#define MAX(x,y) x>y?x:y
would give the largest among 2 parameters on the call of MAX(a,b)
If we are to write
int j=MAX(2,3);
The preprocessor would replace the statement as
int j=3;
before execution
INLINE:
inline int add(int a, int b)
{
return (a+b);
}
after compiling the code each and every call of this function add in the program is replaced by the body of function