C++ Inline function

In C++, an inline function is a function that is expanded in line when it is called. When an inline function is called, instead of jumping to the function code's address, the compiler replaces the function call with the entire function code. This eliminates the overhead associated with the function call, such as the time required to push and pop the function parameters and jump to the function's address, resulting in faster code execution.

To define an inline function, you can use the inline keyword before the function's return type in the function definition. For example:

re‮ot ref‬:theitroad.com
inline int add(int x, int y) {
    return x + y;
}

When the add() function is called, the compiler replaces the function call with the function's entire code. Therefore, the inline keyword is just a suggestion to the compiler, and it is not guaranteed that the function will be inlined. The compiler may decide not to inline a function, for example, if the function is too large or if it is called from multiple places.