What happens when an object is passed by reference?

Options

  • A. Destructor is called when called explicitly
  • B. Destructor is called at end of function
  • C. Destructor is not called
  • D. Destructor is called when function is out of scope

Correct Answer (Detailed Explanation is Below)

C. Destructor is not called

Detailed Explanation

Explanation:

In C++, when an object is passed by reference, no new copy of the object is created.

Since no new object is created:

  • The copy constructor is not called

  • The destructor is not called at the end of the function

The function simply works with the original object.

OOps! You are currently offline.