The title almost says it all but: 1. I am reading a tutorial about character sequences and encountered a section that I do not really understand. They initialize an array of characters with a null character at the end like so:
char myword[] = { 'H', 'e', 'l', 'l', 'o', '\0' };
However, they do not really explain anything further about the null character(I have also tried to use google but sadly I did not find the answer I want). The tutorial says
"By convention, the end of strings represented in character sequences is signaled by a special character: the null character"
which to me means "Most of the times but not every time, a null character is used." So my first question is - When is the null character being used and when do you know if you have to input it explicitly?
2.. I have this code:
char foo[22] = { 'H', 'e', 'l', 'l', 'o' };
cout << foo << endl;
Where the output is: Hello
But this is without me adding the null character and in the tutorial, they initialize the the array with a null character at the end as I showed previously even though that the output of both examples is the exact same?? :/
So my second question is - What is it actually that the null character do?
Thanks, your time is much appreciated!