Inline Functions – Object Oriented Programming (OOP)

Download our Android App from Google Play Store and start reading Reference Notes Offline.

inline functionsInline Functions – Reference Notes
Object Oriented Programming (OOP)
Third Semester | Second year
BSc.CSIT | Tribhuvan University (TU)

Inline Functions
An inline function is written in one line when they are invoked. These functions are very short, and contain one or two statements. Inline functions are functions where the call is made to inline functions. The actual code then gets placed in the calling program.

Normally, a function call transfers the control from the calling program to the function and after the execution of the program returns the control back to the calling program after the function call. These concepts of function save program space and memory space and are used because the function is stored only in one place and is only executed when it is called. This execution may be time consuming since the registers and other processes must be saved before the function gets called.

The extra time needed and the process of saving is valid for larger functions. If the function is short, the programmer may wish to place the code of the function in the calling program in order for it to be executed. This type of function is best handled by the inline function.

The inline function takes the format as a normal function but when it is compiled it is compiled as inline code. The function is placed separately as inline function, thus adding readability to the source program. When the program is compiled, the code present in function body is replaced in the place of function call.

General Format of inline Function:
The general format of inline function is as follows;
inline datatype function_name(argument)

The keyword inline specified in the above example, designates the function as inline function. For example, if a programmer wishes to have a function named college with return value as integer and with no arguments as inline it is written as inline int college.

Program to show example of inline function
using namespace std;
int college(int a);
void main()
int x;
cout<<"Enter the Input value:"; cin>>x;
cout<<"The output is:"<<college(x);
inline int college(int x)
return 5*x;

Enter the Input value:10
The output is:50
Press any key to continue

(Visited 380 times, 1 visits today)

Posted By : Digvijay | Comment RSS | Category : Third Semester
Tag :

Post a Comment

Your email is never published nor shared. Required fields are marked *


Wordpress DMCA
Community | Toolbar | Android App | Founder/Developer : Hari Prasad Chaudhary | CSIT Portal Manager : Digvijay Chaudhary