Home » Learn C++ » Inline Functions

Inline Functions

Inline Functions:

            The inline functions are a special function used for small functions. It is a user-defined function hut in it the function prototype is omitted. The keyword “inline” is used in the decelerator on the function definition. The “inline” function is defined before the main function. When a compiler compiles the source code, it generates a special code at the function call to jump to the function definition.

                            It again generates a code at the end of the function definition to jump hack to the calling function. Thus time is spent in passing the control to the function body and then hack to the calling function during execution of the program.

            The Code of body of the function can he inserted at each place of function call to save the jumping time during program execution. By using the keyword “inline” in the decelerator of the function definition, the code of the function body is inserted at the place of function call during compilation. Such types of functions are called inline functions.

            The inline functions are normally used for small functions.

 

Program: Write a program to find the exponential power of a given number.

 

#include <iostream.h>
#include <conio.h>
inline int expp (int b, int e)
{
int c, pp = l;
for (c=1; c<=e; c++)
pp* = b;
return pp;
}
main( ) 
int n, p, res;
clrscr ( );
cout << “Enter any number ?” ;
cin >> n;
cout << “Enter raise to the power ?” ;
cin >> p;
cout << expp (n, p);
getch ( );
}

            In the above program, the function prototype is not given and the function definition is given before the main function.

Other Topics

comment closed

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
Copyright © 2010 Information Village. All rights reserved.