Inline Function- Program And Its Uses

inline function
inline function

Inline Function:-

The function that is declared with the help of keyword ‘inline’ is known as Inline Function.

It is a function that will expand inline at each point in a program where it is invoked. Also we can say that function body is inserted at the place of function calling whenever the compiler compiles the program so that compiler do not have to go at function definition again and again for each function call.

Like this overheads of compiler will reduced and execution time improves.

Whenever a function is called the following task will be performed,

  1. Storing the memory address of instructions that are used.
  2. The different type of values will be saved in registers.
  3. Actual arguments are pushed or inserted  onto the stack.
  4. Arguments of called function will be popped or deleted from the stack.

 

Syntax,

inline  <returntype> <functionname>(parameters)

{

Fuction Body

}

Program,

#include<iostream.h>

#include<conio.h>

inline int maximum(int x, int y)

{

return (x>y? x: y);

}

void main ()

{

clrscr();

int m= 11, n= 25;

int a, b;

a= maximum(16, 18);

cout<<” Maximum of 16 and 18 is:- “<<a;

b= maximum(m, n);

cout<<” \nMaximum of “<<m<<” and ”<<n<<” is:-“<<b;

}

Output:-

Maximum  of  16  and 18 is:-1 8

Maximum of  11  and  25 is:- 25

You Also Can Visit For More Knowledge In C++:-

Visit Your YouTube  Channel:-  Think , About It

Visit Your Website :- www.atozlives.com

Thanks,

“Play With All Computer Science , Mathematics  And Technology.”

 

 

4 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here