Question:

Which of the following is not the benefit of using an inline function in C++?
(A).It can improve code readability and reduce function call overhead.
(B).It can make the code more modular and easier to maintain.
(C).It allows for dynamic function calls at runtime.
(D).It can be used to define recursive functions.
Choose the correct answer from the options given below:

Show Hint

Remember that `inline` is a compile-time suggestion to the compiler to trade a potential increase in code size for a decrease in function call overhead. It is incompatible with runtime behaviors like dynamic dispatch (virtual functions) and recursion.
Updated On: Sep 24, 2025
  • (A), (B) and (D) only.
  • (A), (B) and (C) only.
  • (A), (B), (C) and (D).
  • (B), (C) and (D) only.
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is D

Solution and Explanation

Step 1: Understanding the Concept:
An inline function in C++ is a hint to the compiler to perform "inlining" - that is, to replace the point of the function call with the actual code of the function body at compile time. This is done to avoid the overhead of a function call (stack setup, branching). The question asks to identify statements that are NOT benefits of this feature. The question structure is highly confusing, as it asks for a single "not benefit" but then provides combination options. We will interpret this as "Which of the following statements are false or describe limitations, rather than benefits, of inline functions?"
Step 2: Detailed Explanation:
Let's analyze each statement:
(A) It can improve code readability and reduce function call overhead: Reducing function call overhead is the primary purpose and benefit of inlining. This is a TRUE benefit.
(B) It can make the code more modular and easier to maintain: Using a function, inline or not, promotes modularity. This is a TRUE benefit.
(C) It allows for dynamic function calls at runtime: This is FALSE. Inlining is a compile-time substitution. It is the antithesis of dynamic calls (like virtual functions), which are resolved at runtime. A function that needs to be called dynamically (e.g., via a function pointer or a virtual dispatch) cannot be inlined. This is a LIMITATION, not a benefit.
(D) It can be used to define recursive functions: This is FALSE. A compiler cannot inline a recursive function because it would lead to infinite expansion of code at compile time. The compiler will simply ignore the `inline` keyword for recursive functions and perform a normal function call. This is a LIMITATION, not a benefit.
Step 3: Final Answer:
Statements (C) and (D) describe limitations or things that inline functions cannot do; they are therefore "not benefits". Statements (A) and (B) describe true benefits. The question asks for what is not a benefit. Therefore, (C) and (D) are the correct items. The provided options are flawed as there is no "(C) and (D) only" option. Let's analyze the given answer, option (4): (B), (C), and (D) only. This option correctly identifies (C) and (D) as "not benefits" but incorrectly includes (B). In the context of a flawed multiple-choice question, this is the option that contains the most correct "not benefits" and is the likely intended answer, assuming an error was made in including (B).
Was this answer helpful?
0
0

Questions Asked in CUET PG exam

View More Questions