Advertisement

Inline Function in C++ - Code with abuzar


         Inline Function

https://abuzartec.blogspot.com/2021/04/inline-function-in-c-code-with-abuzar.html

One of the objective of using function in a program is to save memory spaces , which become appreciable when a function is likely to be called many times . However , every time a function is called . it takes a lot of time to take executing a series of instruction of task such as jumping to the functions , saving register , pushing argument to the stack , and returning to the calling function . One solution is used to this program is to use macro definitions , popularly known as  macros . preprocessor macros are popular in C .

C++ has a different solution to this problem . to eliminate the cost of call to small functions in C++ proposes a new features called a inline function . A inline function is a function that is expended in a line when it is invoked . This is ,  compiler replace the function call with the corresponding function code ( something similar to macros expansion )

The Inline function is define as follows .

Inline functionheader

{

Function body

}

Example

#include<iostream>

Using namespace std ;

Inline float mul ( float x , float y )

{

Return (x*y) ;

}

Inline double div ( double p , double p ) 

{

Return ( p/q)

}

Int main ( )

{

Float a = 12.345

Float b = 9.82

Cout <<mul ( a , b ) <<”\n”;

Cout << div ( a ,b ) << \n”; 

Return 0 ;

}


 Output

121 . 228

1.25713

 

 Please! write comment if you find anything incorrect .

This article is contributed by Mohd Abuzar . if  you like code with abuzar and would like to

 contribute you can also write an article or mail at abuzar.abuzar.mohd325@gmail.com .


 


Post a Comment

0 Comments