Choose the correct statement about inline function in C++.
2023
Choose the correct statement about inline function in C++.
- A.
It speeds up the execution.
- B.
It slows down the execution.
- C.
It decreases the code size.
- D.
More than one of the above
- E.
None of the above
Attempted by 191 students.
Show answer & explanation
Correct answer: A
Inline functions in C++ are a suggestion to the compiler to replace function calls with the function body, reducing the overhead of function calls. This can improve execution speed, especially for small functions called frequently. However, inlining increases code size because the function code is duplicated at each call site. Therefore, excessive inlining may lead to larger executables and potentially slower performance due to increased cache pressure. The compiler decides whether to inline based on heuristics, and the 'inline' keyword is just a hint.