Inline Functions

One of the objective of using functions in a program is to save some memory space, memory becomes appreciable when a function is likely to be called many times. However, every time a function is called, it take a lot of extra time in executing a series of instruction for tasks such as jumping to the function. When a function is small, a substantial percentage of execution time may be spent in such overheads.
C++ has a different solution to this problem. To eliminate the cast of calls to small functions, C++ proposes a new feature called inline function. An inline function is a function that is expanded in line when it is invoke. That is, the compiler replace the function call with the corresponding function code. The inline functions are define as fallows:
inline function-header
{
function body
}
Example:
inline double cube(double a)
{
return(a*a*a);
}

The above inline function can be invoked by statements like
c = cube(3.0);
d = cube(2.5+1.5);

1 comment:

  1. Videoslots.com is a premium site that offers unique features and experiences
    YouTube slots is the official website of the YouTube slots developer. It started as a youtube converter to mp3 premium site with the same name and

    ReplyDelete