+ 2

What is inline function?

11th Mar 2018, 9:20 AM
Suyog Pawar
Suyog Pawar - avatar
2 Answers
+ 3
In c++, Inline functions are used to reduce the function call overhead. It is a function that is expanded in line when it is called. When the inline function is called whole code of the inline function gets inserted or substituted at the point of inline function call. This substitution is performed by the C++ compiler at compile time. It speeds up program by avoiding function calling overhead. It also save overhead of variables push/pop on the stack, when function calling happens. It also increases locality of reference by utilizing instruction cache. example: #include <iostream> using namespace std; inline int min(int a, int b) { return (a> b)? b : a; } int main() { cout << "Minimum number is: " << min(5,10) << endl; return 0; }
11th Mar 2018, 9:35 AM
Vijay
Vijay - avatar
0
usually inline function are small with 2 or 3 lines of codes. but.. INLINE Function would be inefficient if: 1. A Loop is used in the function 2. The function contains complex conditions
11th Mar 2018, 1:33 PM
‎ ‏‏‎Anonymous Guy