Test Series - cpp

Test Number 33/102

Q: Pick the other name of operator function.
A. function overloading
B. operator overloading
C. member overloading
D. object overloading
Solution: Operator function means operation defined for that operator so if user defines a function for an operator then that is called operator overloading i.e. overloading already present operator function.
Q: Which of the following operators can’t be overloaded?
A. ::
B. +
C. 
D. []
Solution: :: operator cannot be overloaded because this operator operates on names rather than values and C++ has no syntax for writing codes that works on names than values so using syntax these operators cannot be overloaded.
Q: How to declare operator function?
A. operator sign
B. operator
C. name of the operator
D. name of the class
Solution: We have to declare the operator function by using the operator, operator sign. Example “operator +” where the operator is a keyword and + is the symbol need to be overloaded.
Q: Which of the following statements is NOT valid about operator overloading?
A. Only existing operators can be overloaded
B. The overloaded operator must have at least one operand of its class type
C. The overloaded operators follow the syntax rules of the original operator
D. None of the mentioned
Solution: The overloaded operator must not have at least one operand of its class type.
Q: Operator overloading is ___________
A. making c++ operator works with objects
B. giving new meaning to existing operator
C. making the new operator
D. adding operation to the existing operators
Solution: Operator overloading is the way adding operation to the existing operators.
Q: What is operator overloading in C++?
A. Overriding the operator meaning by the user defined meaning for user defined data type
B. Redefining the way operator works for user defined types
C. Ability to provide the operators with some special meaning for user defined data type
D. All of the mentioned
Solution: Operator overloading helps programmer to give his/her own meaning to an operator for user defined data types(eg, classes).
Q: What is the syntax of overloading operator + for class A?
A. A operator+(argument_list){}
B. A operator[+](argument_list){}
C. int +(argument_list){}
D. int [+](argument_list){}
Solution: The general syntax for operator overloading is:
return_type operator_keywordOperator(argument_list){}
eg.
A opeartor+(argument_list){}
Q:  How many approaches are used for operator overloading?
A. 1
B. 2
C. 3
D. 4
Solution: There are 3 different approaches used for operator overloading:
i. Overloading unary operator.
ii. Overloading binary operator.
iii. Overloading binary operator using a friend function.
Q: Which of the following operator can be overloaded?
A. ?:
B. ::
C. .
D. ==
Solution: ?:, :: and . cannot be overloaded whereas == can be overloaded.
Q: In the case of friend operator overloaded functions how many maximum object arguments a binary operator overloaded function can take?
A. 1
B. 2
C. 3
D. 0
Solution: In the case of friend operator overloaded functions binary operator overloaded function should take maximum two object argument.

You Have Score    /10