If I write
char* s = “something”;
s[0] = ‘t’;
It will give error !!
char s[] = “something”;
s[0] = ‘t’;
this works why??
If I write
char* s = “something”;
s[0] = ‘t’;
It will give error !!
char s[] = “something”;
s[0] = ‘t’;
this works why??
One more thing to mention that
in the case of:
char* s = “smthg”;
i can access the data like this:
cout << s[0] << endl;
But I cannot change the data:
s[0] = ‘t’; // gives error
And if i print the addresses, both are different…
cout << (void*)x << endl;
cout << (void*)x[0] << endl;
this is bcz most of the times string literals are stored in read only memory, so it shows error when you try to update