Inline function:

Inline function:

If a function is declare as inline then while compilation compiler will replace compiler call with code of function insted of its address.due to this execution speed of program increases as overhead require to call a function are removed.
Inline have functions provide following advantages:
1] Function call overhead doesn’t occur.
2] It also saves the overhead of pop/push variables on the stack when function is called.
3] It also saves overhead of a return call from a function.
4] When you inline a function, we may enable compiler to perform context specific optimization on the body of function. Such optimizations aren’t possible for normal function calls. Other optimizations can be obtained by take accounting the flows of calling context and the called context.
5] Inline function may be useful (if it is small) for embedded systems because inline can generate less code than the function call preamble and return.

Example 1
#include<iostream.h>

inline int sqr(int x)

{

int y; y = x * x; return y;

}

int main()

{

int a =3, b;

b = sqr(a);

cout <<b;

return 0;

}

Output
9
Example 2
#include<iostream.h>

#include<conio.h>

class linee

{

public: inline float mul(float x1,float y1)

{

return(x1*y1);

}

inline float cube(float x1)

{

return(x1*x1*x1);

}

};

void main()

{

linee obj;

float vale1,vale2;

clrscr();

cout<<“Enter two values:”;

cin>>vale1>>vale2;

cout<<“\nMultiplication value is:”<<obj.mul(vale1,vale2); cout<<“\n\nCube value is :”<<obj.cube(vale1)<<“\t”<<obj.cube(vale2); getch();

}

Output
Enter two values:56

67

Multiplication value 3752

Cube value is :175616 300763

Leave a Reply

Your email address will not be published. Required fields are marked *