Ex12 null terminator

Please see the above picture.
I tried to print full_name without ‘/0’ and it still prints the correct full_name other than printing random junk until hits /0.

As far as I know, char name[] = “Zed” will auto-fill \0 in the end, but if you initialize char by char, you have to manually write \0 in the end.

That’s an interesting find, and you’re probably right. You could check it by using a for-loop to go through each character and print out it’s hex code. Make sure the size of the array is known then go through it.

So I tried to print the full_name array and also 3 chars after it. It seems that the compiler automatically adds \0 at the end of the char array, just like it does to name array?

Careful, the rules for when C pads with zero or not are super complex. You might just have randomly got lucky and there were already 3 zeroes there. Rather than memorize all the rules, just add the extra \0 and save yourself the trouble. The only time to rely on it is when it’s known to be guaranteed initialized, like with your “Zed” line or when initializing with a first 0 or structs.