C++ MCQs on Operator Overloading with explanations

OPERATOR OVERLOADING

1. Operator overloading means

Explanation ≡ Correct answer: option a) Giving new meanings to the existing C++ operators
Operator overloading allows us to redefine the behavior of existing C++ operators for user-defined classes or data types. By overloading operators, we can provide custom implementations for how the operators work with our user-defined types.

2. Which of the following operators cannot be overloaded?

Explanation ≡ Correct answer: option a) Scope resolution operator (::)
The scope resolution operator (::), sizeof operator, and member access operator (.* and ->*) cannot be overloaded. Other operators can be overloaded to provide custom behavior for user-defined types.

3. Operator overloading is used to

Explanation ≡ Correct answer: option d) Support run-time polymorphism
Operator overloading is used to provide custom behavior for operators in user-defined classes. This allows the same operator to behave differently based on the data types involved. It enables run-time polymorphism as the specific overloaded operator function to be called is determined at runtime based on the data types of the operands.

4. State which of the following statements is TRUE.

Explanation ≡ Correct answer: option d) The overloaded operator must have at least one operand that is of user-defined type.
Operator overloading is applicable to operators where at least one operand is a user-defined type, i.e., a class or a structure. Operator functions can return values, and they may or may not have arguments depending on the operator being overloaded. Friend functions can be used for operator overloading to provide custom behavior for the operators.

5. State which of the following statements is FALSE.

Explanation ≡ Correct answer: option b) Friend functions can be used to overload all the overloadable operators.
While friend functions can be used to overload many of the overloadable operators, not all operators can be overloaded using friend functions. Some operators, such as the scope resolution operator (::), cannot be overloaded at all. Unary operators overloaded by means of a member function typically take one implicit argument, while binary arithmetic operator functions must return a value explicitly.

6. When overloading binary operators using friend functions, the operator function uses

Explanation ≡ Correct answer: option c) One explicit argument
When overloading binary operators using friend functions, the operator function takes two operands as arguments, but only one of them is explicitly provided as an argument to the operator function. The other operand is accessed through the friend function's parameter list. For example, if the operator being overloaded is the '+' operator, the friend function takes one explicit argument (usually the left operand) and accesses the other operand (usually the right operand) implicitly.

7. When overloading binary operators using member functions, the operator functions use

Explanation ≡ Correct answer: option a) Two explicit arguments
When overloading binary operators using member functions, the operator function takes two explicit arguments: the current object (implicitly accessed through the 'this' pointer) and the other operand passed as a parameter. For example, if the operator being overloaded is the '+' operator, the member function takes one explicit argument (the right operand) and implicitly accesses the current object as the left operand.

8. We can use a constructor function for accomplishing

Explanation ≡ Correct answer: option a) Conversion from class type to class type.
Constructors can be used for type conversion, which allows the compiler to implicitly convert one class type to another through a constructor. This is known as a user-defined conversion or conversion constructor. However, constructors cannot be used to convert from a class type to a basic type or vice versa.

9. The casting operator function can be used to accomplish the conversion

Explanation ≡ Correct answer: option b) Basic type to class type
The casting operator function (conversion operator) can be used to convert a basic type to a class type or vice versa. It allows us to define how to convert an object of one type to another type using the specified casting operator. For example, we can define a casting operator function in a class to convert an int to an object of that class or vice versa.

10. The casting operator function must

Explanation ≡ Correct answer: option a) Be a class member
The casting operator function (conversion operator) must be a member function of the class and cannot be a standalone or non-member function. It allows for converting objects of the class type to the specified type or vice versa. The casting operator function must specify the return type, and it may or may not have arguments based on whether the conversion is from class type to another type or vice versa.


Your Score is 10

THE STUDENT FRIENDLY BOOK TO LEARN C++. THE EXPLANATIONS ARE IN SIMPLE ENGLISH AND THEY PROVIDE EXERCISES TO MAKE YOUR LEARNING EXCELLENT.

Topic wise C++ MCQs Index ≡ (Click to open)
Click on particular topic to visit that page
  1. Principles of Object-Oriented Programming 
  2. Beginning with C++
  3. Tokens, Expressions, and Control Structures
  4. Functions in C++
  5. Classes and Objects
  6. Constructors and Destructors
  7. Operator Overloading
  8. Inheritance
  9. Pointers, Virtual Functions, and Polymorphism
  10. Managing Console I/O Operations
  11. Working with Files
  12. Templates
  13. Exception Handling
  14. Standard Template Library
  15. Manipulating Strings
  16. New Features in ANSI C++ Standards
  17. Object-Oriented System Development

Post a Comment

0 Comments