Object Oriented Programming using C++ Questions and Answers – Member Operator Function

This set of Object Oriented Programming using C++ Questions and Answers for Aptitude test focuses on “Member Operator Function”.

1. Which among the following are valid ways of overloading the operators?
a) Only using friend function
b) Only using member function
c) Either member functions or friend functions can be used
d) Operators can’t be overloaded
View Answer

Answer: c
Explanation: The operators can be overloaded by using the member function or even the friend functions can be used. This is because both of these can access all the data members of a class.

2. Which among the following is mandatory condition for operators overloading?
a) Overloaded operator must be member function of the left operand
b) Overloaded operator must be member function of the right operand
c) Overloaded operator must be member function of either left or right operand
d) Overloaded operator must not be dependent on the operands
View Answer

Answer: a
Explanation: The operator to be overloaded must be made the member function of the operand on left side of expressions to be used. This allows the compiler to identify whether the overloading has to be used or not. This rule also reduces the ambiguity in code.

3. When the operator to be overloaded becomes the left operand member then ______________
a) The right operand acts as implicit object represented by *this
b) The left operand acts as implicit object represented by *this
c) Either right or left operand acts as implicit object represented by *this
d) *this pointer is not applicable in that member function
View Answer

Answer: b
Explanation: The left operand becomes the object that is referred by *this pointer in the member function that will be called while using operator overloading. This is done to point to a specific object on which the overloading will be applied.
advertisement
advertisement

4. If the left operand is pointed by *this pointer, what happens to other operands?
a) Other operands are passed as function return type
b) Other operands are passed to compiler implicitly
c) Other operands must be passed using another member function
d) Other operands are passed as function arguments
View Answer

Answer: d
Explanation: The operands that are used during overloading expect the left operand, can be passed as function arguments. Those are then referred in function definition with the names specified in the argument list.

5. If a friend overloaded operator have to be changed to member overloaded operator, which operator should be used with the class name?
a) Scope resolution operator
b) Colon
c) Arrow operator
d) Dot operator
View Answer

Answer: a
Explanation: The scope resolution operator can be used followed by the class name. Then the operator keyword with the operator symbol that should be overloaded. This is done to use member function instead of friend function.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. What is the syntax to overload an operator?
a) className::operator<operatorSymbol>(parameters)
b) className:operator<operatorSymbol>(parameters)
c) className.operator<operatorSymbol>(paramteres)
d) className->operator<operatorSymbol>(parameters)
View Answer

Answer: a
Explanation: The class name is followed by the scope resolution operator. This is done to specify the class to which the function should belong to. Then the keyword operator should be used in order to indicate the operator that is to be overloaded. Then come the parameters list to specify other operands.

7. Why the left parameter is removed from parameter list?
a) Because it is of no use
b) Because it is never used in definitions
c) Because it becomes parameter pointed by *this
d) Because it can’t be referred by *this pointer
View Answer

Answer: c
Explanation: The left object is removed from being passed as a parameter, because it is implicitly passed. It is passed implicitly because it is considered the object with respect to which the overloading function is being called.
advertisement

8. Which object’s members can be called directly while overloading operator function is used (In function definition)?
a) Left operand members
b) Right operand members
c) All operand members
d) None of the members
View Answer

Answer: a
Explanation: This is because the left operand is passed implicitly. It is pointed by *this. This in turn means we can use the direct member names of the object because those are again converted to a syntax containing *this pointer implicitly.

9. If left operand member is specified directly in the function definition, which is the correct implicit conversion of that syntax?
a) *this className
b) *this parameterObject
c) *this returnedObject
d) *this object
View Answer

Answer: d
Explanation: Since the left operands are passed implicitly, those object members can be accessed directly in the function definition. The compiler converts the syntax into the syntax that can be processed. The implicitly converted syntax contains *this pointer followed by the objectName that is left operand in the expression.
advertisement

10. When the friend operator overloading is converted into member operator overloading _______________
a) Two parameters of friend function remains same parameters in member operator overloading
b) Two parameters of friend function becomes only one parameter of member function
c) Two parameters of friend function are removed while using member function
d) Two parameters of friend function are made 4 in member operator overloading
View Answer

Answer: b
Explanation: The friend function would accept two arguments if some binary operator is overloaded. When we try to convert that definition to member operator overloading then it becomes only one parameter. The reason behind is that the left operand is passed implicitly while using the member functions.

11. Where in the parameter list is the implicit *this is added?
a) Right most parameter
b) Anywhere in parameter list
c) Left most parameter
d) Not added to parameter list
View Answer

Answer: c
Explanation: The left operand is passed implicitly by the compiler to the member function. But this is done, when the compiler adds the calling object as *this to the parameter list. It is always added as the left most parameter, i.e. the first parameter of the function.

12. Which operator among the following can be overloading using only member function?
a) Assignment operator
b) Addition operator
c) Subtraction operator
d) Multiplication and division operator
View Answer

Answer: a
Explanation: Only the assignment operator among the options given must be overloaded using the member functions. The assignment operator can’t be overloaded using friend function. This is a restriction in the programming languages to make the programs more resistant towards errors.

13. Which operator among the following can be overloaded using both friend function and member function?
a) Assignment operator
b) Subscript
c) Member selection (arrow operator)
d) Modulus operator
View Answer

Answer: d
Explanation: Only the modulus operator among the given operators can be overloaded using either friend function or member function. Other operators must be overloaded using only the member functions.

14. All the operators can be overloaded using the member function operator overloading.
a) True
b) False
View Answer

Answer: b
Explanation: It is not the case that all the operators can be overloaded using the member operator overloading. There are some cases where the operators must be overloaded using the friend function only. The reason behind is that the left operand should be passed *this pointer, but the left operand in these cases might be object of some other class. Hence can’t be done.

15. Which operator among the following must be overloaded using the friend function?
a) << operator only
b) >> operator only
c) Both << and >> operators
d) It’s not mandatory to use friend function in any case
View Answer

Answer: c
Explanation: In some cases it is mandatory to use the friend functions for overloading the operators. Here both the << and >> operators must be overloaded using friend function because the left operand is object of some other class and the right operand is usually of some different type.

Sanfoundry Global Education & Learning Series – Object Oriented Programming (OOPs).

To practice all areas of Object Oriented Programming using C++ for Aptitude test, 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.