Inline Function in C++

Advertisements

Prev Tutorial Next Tutorial

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.

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements