Character pointer to string

When i declare char* szString = "Hello"; and then do the following, szString[0] = 'J';, and then try to print cout << szString; nothing prints, why is that? :)

Is it because i changed one of the characters, or it was not declared const?
Last edited on
Because trying to modify string literal is undefined behavior. Often it leads to crash. Sometimes it is not. Sometimes nothing happens. Sometimes it works as expected. Sometimes it changes all similar literals. Sometimes something else happens.

Making char* point to string liteals is deprecated in modern C++. Correct type for it is const char* (or, better, use std::string)
Topic archived. No new replies allowed.