Inline Function in C++
Advertisements
Inline Function in C++
Inline Function is powerful concept in C++ programming language. If a function is inline, the compiler places a copy of the code of that function at each point where the function is called at compile time.
To make any function inline function just preceded that function with inline keyword.
Why use Inline function
Whenever we call any function many time then, it take a lot of extra time in execution of series of instructions such as saving the register, pushing arguments, returning to calling function. For solve this problem in C++ introduce inline function.
Advantage of Inline Function
The main advantage of inline function is it make the program faster.
Syntax
inline function_name() { //function body }
Example
#include<iostream.h> #include<conio.h> inline void show() { cout<<"Hello world"; } void main() { show(); // Call it like a normal function getch(); }
Output
Hello word
Where inline function not work ?
- If inline function are recursive
- If function contain static variables.
- If return statement are exits but not return any value.
Google Advertisment