What is Inline Function?

Asked 06-Dec-2019
Viewed 532 times

1 Answer


0

Inline function is one of the most important features in C++ programming

Inline function is a function that is expanded in the line at which it is called. When the inline function is called, the whole code of the inline function gets inserted or substituted at the point of the calling of the inline function. This substitution is performed by the C++ compiler during the compile time. Inline function may increase the efficiency of the program if it is small. Inlining is only a request to the compiler not a command. The compiler can ignore the request for inlining. Compiler may not perform inlining in circumstances if the function contains : 

  • A loop
  • Contains static variables
  • Is recursive
  • Contains switch or goto statement

Advantages of inline function : 

  • Function call overhead does not occur.
  • It saves the overhead of a return call from a function
  • It saves the overhead of push/pop variables on the stack when function is called