Example:1 (Program to display a value)
#include <iostream> using namespace std; 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; }
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.