C++ Programming Questions and Answers – Overloaded Function Names

This section on C++ language interview questions and answers focuses on “Overloaded Function Names”. One shall practice these interview questions to improve their C++ programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ language interview questions come with detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ language interview questions on “Overloaded Function Names” along with answers, explanations and/or solutions:

1. Which of the following permits function overloading on c++?
a) type
b) number of arguments
c) type & number of arguments
d) number of objects
View Answer

Answer: c
Explanation: Both type and number of arguments permits function overloading in C++, like
int func(int);
float func(float, float)
Here both type and number of arguments are different.

2. In which of the following we cannot overload the function?
a) return function
b) caller
c) called function
d) main function
View Answer

Answer: a
Explanation: While overloading the return function, it will rise a error, So we can’t overload the return function.

3. Function overloading is also similar to which of the following?
a) operator overloading
b) constructor overloading
c) destructor overloading
d) function overloading
View Answer

Answer: b
Explanation: In constructor overloading, we will be using the same options availed in function overloading.
advertisement
advertisement

4. What will be the output of the following C++ code?

  1.     #include <iostream>
  2.     using namespace std;
  3.     void print(int i)
  4.     {
  5.         cout << i;
  6.     }
  7.     void print(double  f)
  8.     {
  9.         cout << f;
  10.     }
  11.     int main(void)
  12.     {
  13.         print(5);
  14.         print(500.263);
  15.         return 0;
  16.     }

a) 5500.263
b) 500.2635
c) 500.263
d) 500.266
View Answer

Answer: a
Explanation: In this program, we are printing the values and the values will be print(5) will be printed first because of the order of the execution.
Output:

Note: Join free Sanfoundry classes at Telegram or Youtube
$ g++ over.cpp
$ a.out
5500.263

5. What will be the output of the following C++ code?

advertisement
  1.     #include <iostream>
  2.     using namespace std;
  3.     int Add(int X, int Y, int Z)
  4.     {
  5.         return X + Y;
  6.     }
  7.     double Add(double X, double Y, double Z)
  8.     {
  9.         return X + Y;
  10.     }
  11.     int main()
  12.     {
  13.         cout << Add(5, 6);
  14.         cout << Add(5.5, 6.6);
  15.         return 0;
  16.     }

a) 11 12.1
b) 12.1 11
c) 11 12
d) compile time error
View Answer

Answer: d
Explanation: As one can observe that no function has declaration similar to that of called Add(int, int) and Add(double, double) functions. Therefore, error occurs.
advertisement

6. What will be the output of the following C++ code?

  1.     #include <iostream>
  2.     using namespace std;
  3.     int operate (int a, int b)
  4.     {
  5.         return (a * b);
  6.     }
  7.     float operate (float a, float b)
  8.     {
  9.         return (a / b);
  10.     }
  11.     int main()
  12.     {
  13.         int x = 5, y = 2;
  14.         float n = 5.0, m = 2.0;
  15.         cout << operate(x, y) <<"\t";
  16.         cout << operate (n, m);
  17.         return 0;
  18.     }

a) 10.0 5.0
b) 5.0 2.5
c) 10.0 5
d) 10 2.5
View Answer

Answer: d
Explanation: In this program, we are divide and multiply the values.
Output:

$ g++ over3.cpp
$ a.out
10	2.5

7. Overloaded functions are ________________
a) Very long functions that can hardly run
b) One function containing another one or more functions inside it
c) Two or more functions with the same name but different number of parameters or type
d) Very long functions
View Answer

Answer: c
Explanation: This is the definition of function overloading i.e. function having same name but different number of parameters and types.

8. What will happen while using pass by reference?
a) The values of those variables are passed to the function so that it can manipulate them
b) The location of variable in memory is passed to the function so that it can use the same memory area for its processing
c) The function declaration should contain ampersand (& in its type declaration)
d) The function declaration should contain $
View Answer

Answer: b
Explanation: In pass by reference, we can use the function to access the variable and it can modify it. Therefore we are using pass by reference.

9. What should be passed in parameters when function does not require any parameters?
a) void
b) blank space
c) both void & blank space
d) tab space
View Answer

Answer: b
Explanation: When we does not want to pass any argument to a function then we leave the parameters blank i.e. func() – function without any parameter.

10. What are the advantages of passing arguments by reference?
a) Changes to parameter values within the function also affect the original arguments
b) There is need to copy parameter values (i.e. less memory used)
c) There is no need to call constructors for parameters (i.e. faster)
d) All of the mentioned
View Answer

Answer: d
Explanation: All the above mentioned are advantages and properties of call by reference.

Sanfoundry Global Education & Learning Series – C++ Programming Language.

To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.