Menu

[Solved] Explain Line Code Need Understand Show Output 1 Include Using Namespace Std Class Int Pub Q37244432

Explain each line of code. I need to understand what it does.Show output.

1)

#include<iostream>
using namespace std;
class A
{
int i;
public:
A(int ii = 0) : i(ii) {}
void show() { cout << i << endl; }
};
class B
{
int x;
public:
B(int xx) : x(xx) {}
operator A() const { return A(x); }
};
void g(A a)
{
a.show();
}
int main()
{
B b(10);
g(b);
g(20);
return 0;
}

2)

#include<stdlib.h>
#include<stdio.h>
#include<iostream>
using namespace std;
class Test {
int x;
public:
void* operator new(size_t size);
void operator delete(void*);
Test(int i) {
x = i;
cout << “Constructor called n”;
}
~Test() { cout << “Destructor called n”; }
};
void* Test::operator new(size_t size)
{
void *storage = malloc(size);
cout << “new called n”;
return storage;
}
void Test::operator delete(void *p )
{
cout<<“delete called n”;
free(p);
}
int main()
{
Test *m = new Test(5);
delete m;
return 0;
}

Expert Answer


Answer to Explain each line of code. I need to understand what it does. Show output. 1) #include using namespace std; class A { in… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *