The literal "hello" sits in read-only memory of the executable, which is there even before the program runs. The variable ais constructed from the literal through:
string::string(const char*)
(actually std::basic_string)
This constructor copies the characters from the literal to the newly created object. If the string is short, then the characters may be copied directly to the memory of the object. Otherwise, a new memory area is allocated, the characters are copied there, and the object points to the new block.
Never does the new object store a pointer to the original literal.
edit
The lines
std::cout << &a;
Takes the address of the object (named a) of type std::basic_string<char>. This object sits on the stack, and is created and destroyed inside int main(). The object does not move, so the pointer is constant and does not change when the string changes. This is the same as the this pointer inside the methods of the std::basic_string<char> of this object.
aisn't a string literal. It's astd::stringthat was constructed using a string literal, but it has its own copy of the data, possibly on the heap. Try"hello"[1] = 'r';and you'll almost certainly get a crash."hello"? I can only see you changinga.42is an integer constant.int a = 42; std::cin >> a;modifies the variablea; that does not mean it is possible to change the value of integer constants.std::string_view(to avoid the copy that std::string does)