in the below code:
#include
#include
using namespace std;
class car
{
private:
int price;
public:
int model_no;
char *name;
car()
{
name=NULL;
cout<<“making a car”<<endl;
}
car(int p,int mn,char*n)
{
price=p;
model_no=mn;
name=new char[strlen(n)+1];
strcpy(name,n);}
void operator=(car x)
{
price=x.price;
model_no=x.model_no;
int l=strlen(x.name);
name=new char[l+1];
strcpy(name,x.name);
}
void print()
{
cout<<name<<endl;
cout<<model_no<<endl;
cout<<price<<endl;
}};
int main()
{
car e;
e.name="bmw";
cout<<e.name<<endl;;//learning--putting semicolon like this will not make any difference because a semicolon just denotes the end of a statement
/e.name[0]=‘r’;
e.name[1]=‘e’;
e.name[2]=’\0’;
cout<<e.name<<endl;/
car c(100,200,“bmw”);
car d(200,400,“audi”);
c=d;
c.name[0]=‘g’;
c.print();
d.print();
return 0;
}
the statements in comments in the main function are not giving any output but the statements above that are giving output.why so?
why we can do e.name=“bmw” but not e.name[0]=‘b’?
also this code is working fine on codeblocks but not working fine on coding blocks ide what is the issue?