I would like to have some confirmation to the following.
I'm compiling and running the following code without any apparent problems, but I reckon is not right, and could lead to experience problems, right? As the first line of code doesn't assign enough memory, to store five characters + a null character.
First code is wrong, and you have said why. That is a buffer overflow that fortunately isn't causing you issues in a small app, but would in a larger one.
"Hello" <-- includes already the zero character. That means you don't have to add \0. \0 defines the end of a string. If you fill a string character by character (dynamically) e.g.
you have to add a zero character to indicate the end of the strings for functions like cout, printf, ...
strings are nt really different to any normal array except that their end is indicated with a 0.