Articles added in Mathematics Lab | Cyber Lab is now open | Astronomy Lab is now open | VLSI Lab is now open | 120 SEO Tips article published | More exciting articles coming soon!




3.6 Inline function

When a function is called, the control will be transferred to the function and after executing the function, the control will be transferred back to the calling point. So, if a function is called several times, this going to the function and coming back will need a considerable extra time which will affect the speed of execution and thus the efficiency of the program.
To solve this problem, C++ supports a special kind of function known as inline function. “inline” is a keyword. An inline function can be defined as:

syntax:
inline return_type function_name(parameters)
{
//body of function
}

During compilation, an inline function will be expanded in line. That means function call will be replaced by the statements of the function. So, after compilation there will be no function calls. This will improve efficiency of the program. But, this will increase the size of the program.

Rules:
--> Inline function should be defined before it is called, i.e., before main.
--> Since inline function is defined before main, no prototype of function is required.
--> All functions cannot be treated as inline function. A function which is simple, doesn’t contain any loops, not a recursive function and without any goto statements can only be treated as inline function. Otherwise one will get warning and request will be ignored.







CACKLE comment system





Programming Resources
Computer Networking Fundamentals Android Application