car(int p,int mn,char* n)
{
price=p;
modelno=mn;
int l=strlen(n);
name=new char[l+1];
strcpy(name,n);
}
int main()
{
car C(100,200,“Audi”);
Here n is the pointer pointing to the string audi.
In this parameterised copy constructor first we are allocating a memory of size (strlen(n)+1) size in heap and pointer (name) is pointing to it.
Then we are doing strcpy(name,n) making name point where n is pointing i.e string audi .
So why are we allocating (strlen(n)+1) size memory in heap ?