Stay Tuned!

Subscribe to our newsletter to get our newest articles instantly!

C++ Programming

C++ – Inline Function and Its Use

Inline Function and Its Use

To minimize the time, an inline function is used. When there are only two or three statements, an inline f() is used. The f() is copied into the main function after it is called.

You must place the keyword inline before the function name and define the function before calling it. The compiler ignores the inline qualifier if the defined function is longer than a line. Even without using the inline specifier, a function definition in a class definition is an inline f() definition.

#include<iostream>
usingnamespace std;
inline
intsubtraction (int a, int b)
{
return (a-b);
}
intmain(void){
cout<<subtraction(5,4);
cout<<subtraction(6,7);
cout<<subtraction(9,4);
return(0);
}  

Drawbacks: Situations, where this function doesn’t work, are,

  1. If a function contains a static variable. 
  2. If the inline f() is recursive. 
  3. For function returning values, if loop, switch, or not exist. 
  4. For function non-returning values it returns statements that exist.
Avatar

Tuts

About Author

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.

You may also like

program to find leap year
C++ Programming

C++ Program to Find Leap Year by Using Function

  • March 3, 2016
Write a program to find if the inputted year is a leap year or not by using the concept of