-->

inline function


Inline function

Explain inline function.
  · To reduce the cost of calls to small functions, C++ proposes a new feature called “inline function“.
  · An inline function is expanded in line when it is invoked.
  · In this the compiler replaces the function call with the corresponding function code.
   ·   Inline functions are defined as follows:
         inline function-header
         {
                 //Function beady
         }

 ·  To define a function inline, inline keyword used as prefix to function header.
         Example:
         inline double cube (double a)
         {
                 return (a * a * a);
         }
·  It makes a program run faster because the overhead of a function call and return is eliminated.
     ·  It must be defined before they are called.

        Situations where inline expansion may not work.
Situation are given below,
     ·       For function returning values, if, a loop, a switch case, or a goto exists.
     ·       For functions not returning values, if a return statement is exists.
     ·       If functions contain static variables.
     ·       If inline functions are recursive.