Explain inline function?
Submitted by: MurtazaAn inline function is a combination of macro & function. At the time of declaration or definition, function name is preceded by word inline.
When inline functions are used, the overhead of function call is eliminated. Instead, the executable statements of the function are copied at the place of each function call. This is done by the compiler.
Consider following example:
#include <iostream>
using namespace std;
inline int sqr(int x)
{
int y;
y = x * x;
return y;
}
int main()
{
int a =3, b;
b = sqr(a);
cout <<b;
return 0;
}
Submitted by: Murtaza
When inline functions are used, the overhead of function call is eliminated. Instead, the executable statements of the function are copied at the place of each function call. This is done by the compiler.
Consider following example:
#include <iostream>
using namespace std;
inline int sqr(int x)
{
int y;
y = x * x;
return y;
}
int main()
{
int a =3, b;
b = sqr(a);
cout <<b;
return 0;
}
Submitted by: Murtaza
Read Online C++ Inline Function Job Interview Questions And Answers
Top C++ Inline Function Questions
☺ | Define Inline Function? |
☺ | Explain what are static member functions? |
☺ | Tell me what happens when recursion functions are declared inline? |
☺ | Please explain, do inline functions improve performance? |
☺ | Explain advantages and disadvantages of using macro and inline functions? |
Top C Plus Plus Language Categories
☺ | C++ Pointers & Functions Interview Questions. |
☺ | C++ Operator Overloading Interview Questions. |
☺ | C++ Exception Handling Interview Questions. |
☺ | C++ Template Interview Questions. |
☺ | C++ Virtual Functions Interview Questions. |