Overloading in C++ MCQ Exercise 35 May 2025 | 2 min read 1. What is the best way to declare a friend function to overload the binary + operator in C ++?
Explanation: The correct answer is option (b). The friend function to overload the binary + operator should be declared with two parameters, both passed by constant reference. 2. Which keyword is used to overload an operator as a non-member function but still access private members?
Explanation: The correct answer is option (a). The friend keyword permits a non-member function to access private members of a class for operator overloading. 3. Can the new and delete operators be overloaded in C++?
Explanation: The correct answer is option (a). In C++, the new and delete operators can be overloaded to access memory allocation and deallocation. 4. Which of the following syntax overloads the unary minus (-) operator for a class?
Explanation: The correct answer is option (c). The unary minus operator - is overloaded as a const member function with no parameters. 5. What is the return type of the overloaded subscript operator [] in a class for read-only access?
Explanation: The correct answer is option (c). Since the subscript operator has read-only access, it must return a constant reference for the element type. 6. Which of the following statements about function call operator() overloading is correct?
Explanation: The correct answer is option (c). The function call() operator can be overloaded to allow objects to be used because they are also functions. Next TopicOverloading-in-cpp-mcq-exercise-4 |
1. What do you mean by friend function in C++? A function that belongs to a class. A function which can access both private members and public members of a class. A function which is defined inside the class. A function that cannot access the members of a class. Show...
3 min read
1. How should a template function be defined with multiple return types? template <T, U> class functionName(U parameter) template class <T, U> functionName(U parameter) template <class T, class U> T functionName(U parameter) template <T, U> functionName(T parameter) Show AnswerWorkspace Explanation: The correct answer is option "a". This syntax defines a template function...
3 min read
1. What will be the output of the following code if the friend function is declared in a namespace? #include<iostream> namespace ns { class A { int x; public: ...
3 min read
1. Which of the following statements, which would be the scope of friend function in C++? Class scope Global scope Protected scope Local Show AnswerWorkspace Explanation: The correct answer is option (b). The friend functions in the c++ will have the global scope since they are not the members of the class. 2....
2 min read
1. Which of the following examples of template specialization is correct? template <> class ClassName<int> { ... }; template <typename T> class ClassName { ... }; template <int> class ClassName { ... }; template <typename T> class ClassName<T> { ... }; Show AnswerWorkspace Explanation: The correct answer is option "a". A particular...
3 min read
1. What is a Variadic template? A template that does not take any arguments A template that can take a variable number of arguments A template that can take only one argument None of the above Show AnswerWorkspace Explanation: The correct answer is option "b". A function or class template in C++...
3 min read
1. Can we overload the assignment operator (=) in C++? Yes No Both None of the above Show AnswerWorkspace Explanation: The correct answer is option (a). In C++, the assignment operator may be overloaded to customize the assignment behavior for a class object. 2. Can a non-member function be used to overload operators...
2 min read
C++ MCQs - Part II These multiple-choice questions and answers (MCQs) on "C++ Programming" focus on all areas of C++ Programming covering almost all topics. These topics are chosen from a collection of the most authoritative and best reference books on C++ Programming. 1) Which of the following...
15 min read
1. Which of the following statement is accurate characteristic overloading in C++? Function overloading is performed by having two or greater functions with equal names and with different or specific return types. Function overloading is carried out by having two or extra functions with identical names but...
2 min read
1. What is the output of the below following C++ Code? #include<iostream> using namespace std; class A { int x; public: A(int val) : x(val) {} friend void modify(A &a); }; void modify(A &a) { a.x += 5; } int main()...
3 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India