Friend Functions in C++
15 questions · 12 min · Medium
Test your knowledge of function overloading in C++, including overloaded functions, parameter lists, return types, ambiguity, default arguments, and compile-time polymorphism.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
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.
B. Parameter type, number, or order
Overloaded functions must have distinguishable parameter lists based on the number, types, or order of parameters.
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.
B. Compile-time polymorphism
Function overloading is resolved by the compiler, so it is considered a form of compile-time polymorphism.
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.
B. They have different parameter counts
The first function accepts one parameter while the second accepts two, so their parameter lists are different.
C. The call can result in an ambiguity error
If overload resolution cannot determine a unique best match, the compiler reports an ambiguous call.
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.
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.
A. At compile time
The compiler performs overload resolution based on the function call and available candidates.
A. Functions
C++ supports function overloading, allowing functions with the same name to have different parameter lists.
A. The int overload is normally selected
An exact match to int is preferred over a conversion from int to double.
A. Yes
Member functions can be overloaded just like non-member functions, provided their parameter lists are distinguishable.
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.
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.