LEC: 15
INLINE FUNCTION
working from function call to function declaration :
This can become overhead if the execution time of function is less than the switching time from the caller function to called function.
- C++ provides an inline functions to reduce the function call overhead. Inline function is a function that is expanded in line when it is called.
- When the inline function is called whole code of the inline function gets inserted or substituted at the point of inline function call.
- This substitution is performed by the C++ compiler at compile time.
NOTE:-
compiler will ignore your request if your function have following:-
- if function contains any loop.
- If function is recursive.
- If function contains switch or goto statements.
- If function have return type other than void.
SYNTAX:
inline return_type function_name(Parameters)
{
...code....
}
CALLING:
function_name(Arguments);
Source Code for Call By value
#include<iostream>
using namespace std;
inline void print(int a)
{
cout<<"The value of a : "<<a<<endl;
}
int main(){
//int a=9;
for(int i=0;i<10;i++)
{
print(i);
}
return 0;
}
#include<iostream> using namespace std; inline void print(int a) { cout<<"The value of a : "<<a<<endl; } int main(){ //int a=9; for(int i=0;i<10;i++) { print(i); } return 0; } |
Comments
Post a Comment