To minimize the time, an inline function is used. When there are only two or three statements, an inline f() is used. The f() is copied into the main function after it is called.
You must place the keyword inline before the function name and define the function before calling it. The compiler ignores the inline qualifier if the defined function is longer than a line. Even without using the inline specifier, a function definition in a class definition is an inline f() definition.
#include<iostream>
usingnamespace std;
inlineintsubtraction (int a, int b)
{
return (a-b);
}
intmain(void){
cout<<subtraction(5,4);
cout<<subtraction(6,7);
cout<<subtraction(9,4);
return(0);
}
Drawbacks: Situations, where this function doesn’t work, are,
- If a function contains a static variable.
- If the inline f() is recursive.
- For function returning values, if loop, switch, or not exist.
- For function non-returning values it returns statements that exist.