C++ Programming

C++ – Inline Function and Its Use

An inline function is used to minimize the time. It is used if there are 2 or 3 statements only. The function is copied to the main function after calling the function.

To use inline a function, place the keyword inline before the function name and define the function before any calls are made to the function.

The compiler can ignore the inline qualifier in case the defined function is more than a line. A function definition in a class definition is an inline function definition, even without the use of the inline specifier.


usingnamespace std;
intsubtraction (int a, int b)
return (a-b);

Drawbacks: Situations where inline function doesn’t work are,

  1. If a function contains a static variable. 
  2. If the inline function is recursive. 
  3. For function returning values, if loop, a switch or got exists. 
  4. For function non-returning values it returns statements exists.

Related Articles

Back to top button

Adblock Detected

Please turn off your Adblocker to view your content.