Sobes.tech
Junior — Middle

What impact does the inline keyword have on program operations?

sobes.tech AI

Answer from AI

The inline keyword in C/C++ serves as a hint to the compiler that the function should ideally be embedded directly at the call site rather than called through the usual function call mechanism.

This reduces the overhead of calling a function (such as jumping to an address, saving registers), which can improve performance, especially for small functions that are called frequently.

Example:

inline int sum(int a, int b) {
    return a + b;
}

int main() {
    int result = sum(3, 4); // the compiler may replace the call with just 3 + 4
}

However, the compiler is not obliged to inline a function if it deems it inefficient. Also, excessive use of inline can increase the size of the final code (code bloat).