Online Classes

Results can only be achieved if you have the focused direction and crystal clear knowledge. To achieve this, you need a mentor. We will help you out by connecting with an expert mentor in the field.

Learn More

Article

Inline Functions in C++ Programming - Codzify.com

3 min 42 sec read

What are Inline Functions ?

To clean up the code we write functions outside the class and this is best way to write any object oriented code. So why Inline Function ?. When we declare any function as inline then while compilation, compiler will replace that call of a function with the exact code whic you had written outside of that class.

In this example , compiler will replace the statement ,

inline void display();
with
void Game :: display()
{
  cout<<abc;
}

Benefit of this inline function is to increase the execution speed of a program . By writing inline it skips the step of function call which actually takes overhead in memory and replaces that line with actual code. So in this way code looks cleaned plus memory saving :)

#include <iostream>
using namespace std;
class Game
{
public:
  int abc;

Game()
{
  abc = 5;
}
inline void display();
}; 

void Game :: display()
{
  cout<<abc;
}

int main()
{
 Game sankeObject;     // Creatig Game class's object
 sankeObject.display();
}

Output :-

5

Try to execute what you have learnt

Easy to use online data structure compiler where you can execute the programs in your favourite programming language.
(C, C++, Python)

Open Compiler

HTML, CSS and Javascript Real time Web Editor

Execute your HTML, CSS and javascript code in real time with the web editor
(HTML, CSS, Bootstrap, Javascript)

Open Web Editor