In normal function, First control will move from calling to called function.
Then arguments will be pushed on to the stack, then control will move back to the calling from called function.
This process takes extra time in executing. To avoid this, we use inline function.
An inline function is expanded whenever it is called.
That is, when we call the inline function the compiler replaces the call with the corresponding function definition, thus saving time of context switching between the calling and called function.
The following program demonstrates the C++ program to find the maximum of two numbers using the inline function.
#include
using namespace std;
inline int max(int x, int y)
{
if (x>y)
return x;
else
return y;
}
int main()
{
int a, b;
cout<<"Enter the first number: ";
cin>>a;
cout<<"Enter the second number: ";
cin>>b;
cout<<"The maximum number is "<
OUTPUT:
READ Wipro ELITE National Talent Hunt Hiring 2021
Enter the first number: 30
Enter the second number: 25
The maximum number is 30