Which statements correctly describe C++ function overloading? Choose all that make two functions with the same name distinct overloads.

Difficulty: Easy

Correct Answer: Both A and B.

Explanation:

Introduction:Function overloading lets multiple functions share a name but differ in their parameter lists. This question checks whether you know which differences produce distinct overloads in C++.

Given Data / Assumptions:

  • Same function name across candidates.
  • We compare parameter lists only (return type alone does not overload).
  • Language: C++ overload resolution rules.

Concept / Approach:Two overloads are distinct if their parameter types differ in number, types, or order. Changing only the return type does not create a new overload. Therefore, differences in argument types or their order both qualify as distinct overloads.

Step-by-Step Solution:1) Evaluate A: different parameter types → valid basis for overloading.2) Evaluate B: different order (e.g., f(int, double) vs f(double, int)) → valid, because the parameter lists are different.3) Evaluate C: “number is same” by itself does not ensure distinctness; they could still be identical. Overloading needs a parameter list difference.4) Hence, the correct choice is “Both A and B.”

Verification / Alternative check:Try compiling void f(int,double); void f(double,int); — both coexist. But int f(int); double f(int); fails because return type alone does not overload.

Why Other Options Are Wrong:A only: incomplete — order differences also qualify.B only: incomplete — type differences also qualify.C: irrelevant condition; sameness of number does not ensure distinct overloads.

Common Pitfalls:Assuming that changing only the return type is sufficient. Also forgetting that default arguments can complicate overload resolution and cause ambiguity.

Final Answer:Both A and B.

More Questions from OOPS Concepts

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion