Machine-translated by Google. Questions are authored in English.
Top

Operator Overloading Questions and Answers

1.

If an arithmetic assignment operator is overloaded in C++ programming the result :

Exam Year(s)

MH SET - 2018, SET Exam - 2018,

Answer: B

The result goes in the object to the left of the operator.

Arithmetic assignment operators such as += and -= modify their left operand. When += is overloaded as a member function, a += b is called as a.operator+=(b): the object on the left is the one that calls the function, and the function changes that object's own data.

The object on the right is only read. The operator may also return a reference to the left object so that assignments can be chained, but returning a result is not required, and the result is stored in the left object whether or not anything is returned.

Please log in or register to report this question.

2.

In C++/C operators such as............ cannot be overloaded.

Exam Year(s)

MH SET - 2018, SET Exam - 2018,

Answer: C

The operator that cannot be overloaded is ::, the scope resolution operator.

C++ allows most operators to be given new meanings for user-defined types, but a few are fixed by the language: the scope resolution operator ::, the member access operator ., the pointer-to-member operator .*, the conditional operator ?: and sizeof. These work on names and types at compile time rather than on values, so overloading them would make the language ambiguous.

The other options, +, ++ and ==, are among the operators most commonly overloaded, for example to add, increment or compare objects of a class.

Please log in or register to report this question.

3.

To overload an operator................. keyword must be used along with the operator to be overloaded.

Exam Year(s)

MH SET - 2018, SET Exam - 2018,

Answer: D

The keyword is operator.

An overloaded operator is defined as a function whose name is the keyword operator followed by the symbol being overloaded. For example, Complex operator+(const Complex &other) const; declares how + works for a Complex class, and the compiler then translates a + b into a call to that function.

'Over' and 'Overload' are not C++ keywords at all. void is a keyword, but it names the empty return type and has nothing to do with overloading operators.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Operator Overloading Questions and Answers || Operator Overloading MCQ Questions and Answers || Operator Overloading GK Questions and Answers || Operator Overloading GK MCQ Questions || Operator Overloading Multiple Choice Questions and Answers || Operator Overloading GK || GK on Operator Overloading || Object Oriented Programming Questions and Answers || Object Oriented Programming MCQ Questions and Answers || Object Oriented Programming GK Questions and Answers || GK on Object Oriented Programming