Overloading In C++ Mcq Exercise 4 - C++ Programming Tutorial
C++ Course / MCQ & Exercises / Overloading In C++ Mcq Exercise 4

Overloading In C++ Mcq Exercise 4

BLUF: Mastering Overloading In C++ Mcq Exercise 4 is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Overloading In C++ Mcq Exercise 4

C++ is renowned for its efficiency. Learn how Overloading In C++ Mcq Exercise 4 enables low-level control and high-performance computing in the tutorial below.

  1. Can we overload the assignment operator (=) in C++?
  • Both
  • None of the above

Explanation:

The correct answer is option (a). In C++, the assignment operator may be overloaded to customize the assignment behavior for a class object.

  1. Can a non-member function be used to overload operators in C++?
  • Both
  • None of the above

Explanation:

The accurate choice is alternative (a). Overloading operators through non-member functions is especially useful when there is a need to access private class members using friend functions.

  1. Which of the subsequent operators is not eligible for overloading in C++?

Explanation:

The correct answer is option (c). The .* operator cannot be overloaded in C++.

  1. Which of the following statements about destructors in C++ is true?
  • Destructors can be overloaded.
  • Destructors cannot be overloaded.
  • Destructors must return an int.
  • Destructors are overloaded automatically.

Explanation:

The correct answer is option (b). Destructors cannot be overloaded, and every class can have only one destructor in C++.

  1. Can constructors be overloaded in C++ programming?
  • Both
  • None of the above

Explanation:

Option (a) is the accurate choice. In C++, constructors can be overloaded by creating two or more constructors with varying parameter lists.

  1. What is the expected result of the code snippet provided below?
Example

#include<iostream>

using namespace std;

class Integer {

    int value;

public:

    Integer(int v): value(v) {}

    friend ostream& operator<<(ostream &out, const Integer &i);

};

ostream& operator<<(ostream &out, const Integer &i) {

    out << i.value;

    return out;

}

int main() {

    Integer i(10);

    cout << i << endl;

    return 0;

}
  • Compilation error
  • Runtime error
  • Undefined behavior

Explanation:

The accurate choice is alternative (a). The << operator has been properly overloaded as a friend function to display the Integer object's value.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience