In C++, we can declare a function as inline. This copies the function to the location of the function call in compile-time and may make the program execution faster.
Before following this tutorial, be sure to visit the C++ Functions.
Inline Functions
To create an inline function, we use the inline keyword. For example,
inline returnType functionName(parameters) {
// code
}
Notice the use of keyword inline before the function definition.
C++ Inline Function
Output
5 8 666
Here is how this program works:
Here, we created an inline function named displayNum() that takes a single integer as a parameter.
We then called the function 3 times in the main() function with different arguments. Each time displayNum() is called, the compiler copies the code of the function to that call location.