Skip to content
QuiznExam

Function Overloading in C++

Test your knowledge of function overloading in C++, including overloaded functions, parameter lists, return types, ambiguity, default arguments, and compile-time polymorphism.

15
Questions
12 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. What is function overloading in C++?

    • A. Defining multiple functions with the same name but different parameter lists
    • B. Defining multiple functions with different names
    • C. Defining the same function multiple times with identical parameters
    • D. Calling a function recursively
    Show answer

    A. Defining multiple functions with the same name but different parameter lists

    Function overloading allows multiple functions to have the same name as long as their parameter lists differ.

  2. 2. Which of the following can be used to distinguish overloaded functions?

    • A. Return type only
    • B. Parameter type, number, or order
    • C. Function body only
    • D. Access specifier only
    Show answer

    B. Parameter type, number, or order

    Overloaded functions must have distinguishable parameter lists based on the number, types, or order of parameters.

  3. 3. Can two functions be overloaded solely by changing their return type?

    • A. Yes, always
    • B. Yes, if the functions are in different classes
    • C. No
    • D. Only when using pointers
    Show answer

    C. No

    C++ does not allow functions to be overloaded based only on their return type because the return type is not sufficient to distinguish the function call.

  4. 4. Which form of polymorphism is function overloading commonly associated with?

    • A. Runtime polymorphism
    • B. Compile-time polymorphism
    • C. Dynamic linking
    • D. Data hiding
    Show answer

    B. Compile-time polymorphism

    Function overloading is resolved by the compiler, so it is considered a form of compile-time polymorphism.

  5. 5. Which of the following is a valid example of function overloading?

    • A. int add(int a, int b); double add(double a, double b);
    • B. int add(int a, int b); int add(int a, int b);
    • C. int add(int a); int add(int a);
    • D. int add(int a, int b); int add(int a, int b) const;
    Show answer

    A. int add(int a, int b); double add(double a, double b);

    The two functions have the same name but different parameter types, making them valid overloads.

  6. 6. Consider `void show(int x);` and `void show(int x, int y);`. What makes these functions overloads?

    • A. They have different return types
    • B. They have different parameter counts
    • C. They have different function names
    • D. They have different access modifiers
    Show answer

    B. They have different parameter counts

    The first function accepts one parameter while the second accepts two, so their parameter lists are different.

  7. 7. What happens if an overloaded function call matches more than one candidate equally well?

    • A. The first function is always called
    • B. The compiler chooses randomly
    • C. The call can result in an ambiguity error
    • D. The program automatically calls all matching functions
    Show answer

    C. The call can result in an ambiguity error

    If overload resolution cannot determine a unique best match, the compiler reports an ambiguous call.

  8. 8. Which statement about function overloading and default arguments is correct?

    • A. Default arguments can never cause ambiguity
    • B. Default arguments can sometimes make overloaded calls ambiguous
    • C. Default arguments disable function overloading
    • D. Default arguments are required for every overload
    Show answer

    B. Default arguments can sometimes make overloaded calls ambiguous

    Default arguments can cause multiple overloaded functions to become viable for the same call, potentially creating ambiguity.

  9. 9. Which overloaded functions have different parameter types?

    • A. void print(int x); void print(double x);
    • B. void print(int x); void print(int x);
    • C. int print(int x); double print(int x);
    • D. void print(); void print();
    Show answer

    A. void print(int x); void print(double x);

    The first function accepts an int and the second accepts a double, so their parameter types distinguish the overloads.

  10. 10. When does the compiler normally determine which overloaded function to call?

    • A. At compile time
    • B. Only at program termination
    • C. At database execution time
    • D. After the program has finished
    Show answer

    A. At compile time

    The compiler performs overload resolution based on the function call and available candidates.

  11. 11. Which of the following can be overloaded in C++?

    • A. Functions
    • B. Only variables
    • C. Only namespaces
    • D. Only comments
    Show answer

    A. Functions

    C++ supports function overloading, allowing functions with the same name to have different parameter lists.

  12. 12. What is the result of calling `display(10)` when the following overloads exist: `display(int)` and `display(double)`?

    • A. The int overload is normally selected
    • B. The double overload is always selected
    • C. Both functions are called
    • D. The compiler always reports ambiguity
    Show answer

    A. The int overload is normally selected

    An exact match to int is preferred over a conversion from int to double.

  13. 13. Can member functions in a C++ class be overloaded?

    • A. Yes
    • B. No
    • C. Only static member functions
    • D. Only private member functions
    Show answer

    A. Yes

    Member functions can be overloaded just like non-member functions, provided their parameter lists are distinguishable.

  14. 14. Which statement about overloaded function names is correct?

    • A. All overloads must have different names
    • B. Overloads share the same function name but have different parameter lists
    • C. Overloads must always have different return types
    • D. Overloads can only exist in separate programs
    Show answer

    B. Overloads share the same function name but have different parameter lists

    The defining feature of function overloading is using the same function name with distinguishable parameter lists.

  15. 15. What is the main advantage of function overloading?

    • A. It allows related operations to use the same meaningful function name
    • B. It eliminates all type conversions
    • C. It makes every function execute at runtime
    • D. It prevents functions from accepting parameters
    Show answer

    A. It allows related operations to use the same meaningful function name

    Function overloading improves readability by allowing related operations to use one descriptive function name while accepting different parameter types or counts.