C++ Programming Multiple Choice Question - Overloading
This section focuses on the "Overloading" in C++ programming langauge. These Multiple Choice Questions (MCQ) should be practiced to improve the C++ programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. Which is the correct statement anout operator overloading in C++?.
A. Only arithmetic operators can be overloaded
B. Associativity and precedence of operators does not change
C. Precedence of operators are changed after overlaoding
D. Only non-arithmetic operators can be overloaded
View Answer
Ans : B
Explanation: Both arithmetic and non-arithmetic operators can be overloaded. Priority and affiliation of operators remain before and after operator overloading.
2. Which of the following operators cannot be overloaded?
A. .* (Pointer-to-member Operator )
B. :: (Scope Resolution Operator)
C. .* (Pointer-to-member Operator )
D. All of the above
View Answer
Ans : D
Explanation: All of the above operator cannot be overloaded.
3. While overloading binary operators using member function, it requires ___ argument?
A. 2
B. 1
C. 0
D. 3
View Answer
Ans : B
Explanation: While overloading binary operators using member function, it requires 0 argument.
4. Which of the following operators should be preferred to overload as a global function rather than a member method?
A. Postfix ++
B. Comparison Operator
C. Insertion Operator <<
D. prefix ++
View Answer
Ans : C
Explanation: Insertion Operator should be preferred to overload as a global function rather than a member method.
5. Which of the following operator functions cannot be global, i.e., must be a member function.
A. new
B. delete
C. Converstion Operator
D. All of the above
View Answer
Ans : C
Explanation: Converstion Operator functions cannot be global, i.e., must be a member function.
6. Which of the following is correct option?
A. x = 5, y = 10
B. x = 10, y = 5
C. Compile Error
D. x = 5, y = 5
View Answer
Ans : A
Explanation: This function call is a simple example of operator overloading. The function call operator, when overloaded, does not modify how the function is called. Rather, it modifies how to interpret the operator when applied to objects of a given type.
7. Which of the following is correct option?
A. x = 15, y = 3
B. x = 3, y = 15
C. Compile Error
D. x = 15, y = 15
View Answer
Ans : B
Explanation: This function call is a simple example of operator overloading. The function call operator, when overloaded, does not modify how the function is called. Rather, it modifies how to interpret the operator when applied to objects of a given type.
8. Which of the following is correct option?
A. lets(int) called
B. lets(lfc 2) called
C. Compiler Error: Ambiguous call to lets()
D. No error and No output
View Answer
Ans : C
Explanation: The class lfc has two conversion operators overloaded, int and lfc1. And there are two lets() for int and lfc1.
9. Which of the following is the correct order involves in the process of operator overloading.
i) Define the operator function to implement the required operations.
ii) Create a class that defines the data type that is to be used in the overloading operation.
iii) Declare the operator function op() in the public part of the class.
A. 1-i, 2-ii, 3-iii
B. 1-ii, 2-iii, 3-i
C. 1-ii, 2-i, 2-iii
D. 1-iii, 2-ii, 3-i
View Answer
Ans : B
Explanation: 1-ii, 2-iii, 3-i is the correct order involves in the process of operator overloading.
10. Which of the following is correct option?
A. Compiler Error
B. 8 10
C. 8 8
D. 10 8
View Answer
Ans : B
Explanation: Note that the class LFC1 has as conversion operator overloaded, so an object of LFC1 can be converted to that of LFC. Also, class LFC has a constructor which can be called with single integer argument, so an int can be converted to LFC.
Also check :
Discussion