I understand that using const char* is a modifiable pointer to a constant character. As such, I can only modify the pointer, but not the character. Because of this, I do not understand why I am allowed to do this:
const char* str{"Hello World"};
str = "I change the pointer and in turns it changes the string, but not really.";
How does this work? Is there somewhere in memory where all the characters are stored and I can just point to them as I wish? Furthermore, the adress of str does not change throughout this process. Since the only thing that can change is the address, I really don't understand what's going on.
Maybe part of the problem is that I try to understand this as if the string was an integer. If I do:
int number{3};
const int* p_number{&number};
*p_number = 4;
This is not valid, hence why I expect str to not by modifiable. In order words, where am I pointing so that "Hello World" becomes "I change the pointer and this changes the string"?
EDIT:
I get that I create a new string at another address, but when I do:
const char *str{"HelloWorld"};
std::cout << &str << std::endl;
str = "I create new string, but I get same address";
std::cout << &str << std::endl;
I always get the same address twice.