I have the following program which is giving run time error: The instruction at "x" referenced memory at "y" The memory could not be written.
int main()
{
char *str1 = "Rain";
char *&str2 = str1;
cout << str1 << str2 << endl;
*str1 = 'M';
cout << str1 << str2 << endl;
*str2 = 'P';//Here the error happens
cout << str1 << str2 << endl;
return 0;
}
What is the cause of this error.