What happens when you attempt to compile and run the following code?

Last Updated on December 5, 2021 by Admin 2

What happens when you attempt to compile and run the following code?

#include <iostream>

using namespace std;

class BaseClass
{
public:
int *ptr;
BaseClass(int i) { ptr = new int(i); }
~BaseClass() { delete ptr; delete ptr;}
void Print() { cout << *ptr; }
};
void fun(BaseClass x);

int main()
{
BaseClass o(10);
fun(o);
o.Print();
}

void fun(BaseClass x) {
cout << “Hello:”;
}

  • It prints: Hello:1
  • It prints: Hello:
  • It prints: 10
  • Runtime error.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments