C++ Programming Questions and Answers – Overloaded Function Names

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:

Q 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

Show Answer Answer:-C. type & number of arguments
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.

Q 2.In which of the following we cannot overload the function?
A. caller
B. return function
C. called function
D. main function

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

Q 3. Function overloading is also similar to which of the following?
A. operator overloading
B. destructor overloading
C. constructor overloading
D. function overloading

Show Answer Answer:-C. constructor overloading
Explanation In constructor overloading, we will be using the same options availed in function overloading.

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

#include using name

space std;
void print(int i)
{
cout << i;
}
void print(double f)
{
cout << f;
}
int main(void)
{
print(5);
print(500.263);
return 0;
}
A. 5500.263
B. 500.2635
C. 500.263
D. 500.266

Show Answer Answer:-A. 5500.263
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

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

#include using name

space std;
int Add(int X, int Y, int Z)
{
return X + Y;
}
double Add(double X, double Y, double Z)
{
return X + Y;
}
int main()
{
cout << Add(5, 6);
cout << Add(5.5, 6.6);
return 0;
}
A. 11 12.1
B. 12.1 11
C. 11 12
D. compile time error

Show Answer Answer:-D. compile time error
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.

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

#include using name

space std;
int operate (int a, int b)
{
return (a * b);
}
float operate (float a, float b)
{
return (a / b);
}
int main()
{
int x = 5, y = 2;
float n = 5.0, m = 2.0;
cout << operate(x, y) <<“\t”;
cout << operate (n, m);
return 0;
}
A. 10.0 5.0
B. 5.0 2.5
C. 10.0 5
D. 10 2.5

Show Answer Answer:-D. 10 2.5
Explanation In this program, we are divide and multiply the values. Output: $ g++ over3.cpp $ a.out 10 2.5

Q 7. Overloaded functions are ____
A. Very long functions that can hardly run
B. One function containing another one or more functions inside it
C. Very long functions
D. Two or more functions with the same name but different number of parameters or type

Show Answer Answer:-D. Two or more functions with the same name but different number of parameters or type
Explanation This is the definition of function overloading i.e. function having same name but different number of parameters and types.

Q 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 function declaration should contain ampersand (& in its type declaration)
C. The location of variable in memory is passed to the function so that it can use the same memory area for its processing
D. The function declaration should contain $

Show Answer Answer:-C. The location of variable in memory is passed to the function so that it can use the same memory area for its processing
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.

Q 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

Show Answer Answer:-B. blank space
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.

Q 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

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

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page