Google Add


Inline Function

Inline function in c++

 The inline function is a function which is expanded in line when it is called. In inline function  the compiler replaces the function call with the function code.

Why we use inline function?

Function defined as inline makes a program execution faster because the overhead of a function call and return is eliminated. 

Syntax of inline function-

inline functionname
//function body


#include <iostream>

inline int sqr(int a)
return (a*a);

void main( )
        int x;
        cout << "Enter the Input Value: ";
        cout << "n The Output is: " << sqr(x);


The functions are made inline when they are small enough to be defined in one or two lines. 

Here are some situation in which inline function may not work.

1. If function contains a loop, a switch statement, or a goto statement.
2. If function contains static variable.
3. If function is recursive.

No comments:

Post a Comment