Doing that reduces the number of weird cases you have to deal with when doing character-by-character comparisons.
alphabet
alpha___
If you stepped through this one letter at a time, and the null padding at the end of alpha
wasn't there, you'd try to examine the next element... and run right off the end of the array.
The null padding basically ensures that when there's a character in one word, there's a corresponding character in the other. And since the null character has a value of 0, the shorter word always going to be considered as 'less than' the longer one!
As to why it seems to work without those lines, there's two associated reasons I can think of:
- This was written in C. C does not guard its array boundaries; you can read whatever junk data is beyond the space that was allocated for it, and you'd never hear a thing.
- Your input document is made such that you never compare two strings where one is a prefix of the other (like
alpha
is toalphabet
).