Initialisation of pointer data member issue

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?

the coding blocks ide for the code is:

although the code is working fine in codeblocks it is not working fine on coding blocks ide

Basically, char *string , these are just pointers to some allocated space in memory.
so when we do char *str = “I Love Coding”, then str is pointer which is just pointing to this string which is allocated somewhere in memory. But when we try to do str[0] or str[1], it doesn’t mean anything as we haven’t allocated any memory space to this pointer.

Also, We cannot modify the string at later stage in program. We can change str to point something else but cannot change value present at str.

I don’t know exactly why it is working on codeblocks, actually the compilers are also a program written in some other languages, so it may be something that their compiler has some other implementation for this.

Hope it helps.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.