Skip to main content
added 70 characters in body
Source Link
bubesh p
  • 111
  • 2
  • 11

I use visual studio 2017

int main() { std::string a = "hello"; std::cout << &a; a[1] = 'r'; std::cout << &a; gives same address as above std::cin.get(); } 

when i hover the mouse pointer over "hello".

It shows const char[6]. So "hello" is stored in read only memory.

then how come it is possible to change the value in it.

screen shot

I use visual studio 2017

int main() { std::string a = "hello"; std::cout << &a; a[1] = 'r'; std::cout << &a; gives same address as above std::cin.get(); } 

when i hover the mouse pointer over "hello".

It shows const char[6]. So "hello" is stored in read only memory.

then how come it is possible to change the value in it.

I use visual studio 2017

int main() { std::string a = "hello"; std::cout << &a; a[1] = 'r'; std::cout << &a; gives same address as above std::cin.get(); } 

when i hover the mouse pointer over "hello".

It shows const char[6]. So "hello" is stored in read only memory.

then how come it is possible to change the value in it.

screen shot

Source Link
bubesh p
  • 111
  • 2
  • 11

where string literals will be stored

I use visual studio 2017

int main() { std::string a = "hello"; std::cout << &a; a[1] = 'r'; std::cout << &a; gives same address as above std::cin.get(); } 

when i hover the mouse pointer over "hello".

It shows const char[6]. So "hello" is stored in read only memory.

then how come it is possible to change the value in it.