Thank you for printing our content at [Link].
Please check back soon for new
contents.
ster-cpp?
m_medium=referral&utm_audience=ORGANIC-
Search tutorials & examples
C++ Inline Functions
(/)
rse_promotion&utm_content=interests_learn_cpp&utm_term=nav_floating_button)
[Link]
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++
(/cpp-programming/function) Functions (/cpp-
programming/function).
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
Thank you for printing our content at [Link]. Please check back soon for new
contents.
ster-cpp?
m_medium=referral&utm_audience=ORGANIC-
Search tutorials & examples
#include
(/) <iostream>
rse_promotion&utm_content=interests_learn_cpp&utm_term=nav_floating_button)
using namespace std;
[Link]
inline void displayNum(int num) {
cout << num << endl;
}
int main() {
// first function call
displayNum(5);
// second function call
displayNum(8);
// third function call
displayNum(666);
return 0;
}
Run Code (/cpp-programming/online-compiler)
Output
5
8
666
Here is how this program works:
Working of inline functions in C++
Here,our
Thank you for printing wecontent
createdatan inline function named
[Link]. Please check back soon for new
displayNum()
contents. that takes a single integer as a parameter.
ster-cpp?
We then called the
Search function
m_medium=referral&utm_audience=ORGANIC-
tutorials 3 times in the main()
& examples
(/)
rse_promotion&utm_content=interests_learn_cpp&utm_term=nav_floating_button)
function with different arguments. Each time
[Link]
displayNum() is called, the compiler copies the code of
the function to that call location.
Next Tutorial:
(/cpp-programming/recursion)
C++ Recursion
Previous Tutorial:
C++ Function (/cpp-programming/function-
overloading)
Overloading
Share on:
([Link] ([Link]
u=[Link] text=Check%20this%2
programming/inline-function) programming/inline-fu
Did you find this article helpful?
Related Tutorials
C++ Tutorial
C++ Functions
(/cpp-programming/function)
C++ Tutorial
C++ Function Overloading
Thank you for printing our content at [Link]. Please check back soon for new
contents.
ster-cpp? (/cpp-programming/function-overloading)
m_medium=referral&utm_audience=ORGANIC-
Search tutorials & examples
(/)
rse_promotion&utm_content=interests_learn_cpp&utm_term=nav_floating_button)
C++ Tutorial
[Link]
C++ Function Template
(/cpp-programming/function-template)
C++ Tutorial
Passing Array to a Function in C++ Programming
(/cpp-programming/passing-arrays-function)