hi i want ask how things get copied when i assign one object s1 to the another object
s3(s3=s1)of the same class string in the following given example,also tell why constructor 1 needs to be initialized like str[0]='\o' ..thanks in advance
#include<iostream.h>
#include<string.h>
#include<conio.h>
const int max=80;
class string
{
private:
char str[max];
public:
string(){str[0]='\0';} /*constructor 1*/
string(char s[]){strcpy(str,s);} /*constructor 2*/
void display(){cout<<str;} /*display*/
void cpycat(string s2 )
{if(strlen(str)+strlen(s2.str)<max)
strcat(str,s2.str);
else
cout<<"string lenght exceeded";
}};
void main()
{
string s1("merry christmas");
string s2=",seasons grettings";
string s3;
cout<<"\ns1 ";s1.display();
cout<<"\ns2 ";s2.display();
cout<<"\ns3 ";s3.display();
s3=s1; /*assign*/
cout<<"\ns3 ";s3.display();
s3.cpycat(s2);
cout<<"\ns3 ";s3.display();
}