Inline Function
Inline Function
BY
Junaid Ali Siddiqui
Inline Function
Functions are used to avoid code duplication. At
each call (to a function), control is passed to the
function at a specified address in the memory.
If the same function is called several times, each
time the control is passed to the function. Due
to this passing of control, execution speed
decreases.
C++ provides a mechanism called ‘Inline
Function’.
Continued…
Compiler copies the code of inline function in the
calling function, i.e. Function body is inserted in
place of function call during compilation. So
transfer of control is avoided.
Inline function are mostly used when the function
is small.
Execution performance is increased but inline
function needs more memory.
Example
inline int square(int j)
{
return (j*j);
}
void main()
{
clrscr();
int p=3,r;
r=square(p);
cout<<“r= ”<<r;
getch();
}
Situation where inline Function may not work