Prateek bhaiya explained that if we change the name that is dynamically assigned it will change the name of the original object as well but this does no happen in my code.
#include
#include
using namespace std;
class Car
{
private:
int price;
public:
int model;
char *name;
Car()
{
name = NULL;
}
Car(float p, int m, char *n)
{
price = p;
model = m;
name = new char[strlen(n) + 1];
strcpy(name, n);
}
void print()
{
cout << "Name : " << name << endl;
cout << “Model :” << model << endl;
cout << “Price :” << price << endl;
}
void set_price(float p)
{
price = p;
}
};
int main()
{
cout << “From car c” << endl;
Car c(1000, 3, “Audi”);
Car d©;
d.name = "AMW";
d.set_price(3000);
c.print();
d.print();
return 0;
}