Inline function in C++ Programming | C++ Programming

Inline function in C++ Programming

A inline function is a short-code function  written and placed before main function  and compiled as inline code. The prototyping is not required for inline function. It starts with keyword inline . In ordinary functions, when function is invoked the control is passed to the calling function and after executing the function the control is passed back to the calling program.
         But , when inline function is called, the inline code of the function is inserted at the place of call and compiled with the other source code together. That is the main  feature of inline function and different from the ordinary function.  So using inline function executing time is reduced because there is no transfer and return back to control. But if function has long code inline function is not suitable because it increases the length of source code due to inline compilation.

// Inline Function
//saves memory, the call to function cause the same code to be
//executed;the function need not be duplicated in memory
inline float lbstokg(float pound)
return (0.453592*pound);
 void main()
float lbs1=50,lbs2=100; 
cout<<"Weinght in Kg:"<<lbstokg(lbs1) <<endl; 
cout<<"Weinght in Kg:" <<lbstokg(lbs2) <<endl; 

Post a Comment