Originally Posted by
xwid
Strings of length 5 contain 5 characters, but the last character is at position 4 because String is an array of char so the last character is [4] because 5-1 = 4.
I just wanted to make it clear.
Sorry, but I don't think that makes it clear. Where does it say that a String is an array of chars? A String is a string of chars, but where does it define the implementation of String to be that of an array?
The last character is not at index four
because five minus one is four. It's there because the first character is at index zero, so the second character is at index one, so the third character is at index two, so the fourth character is at index three, so the fifth character is at index four.
My point is that the "0 index" idea is not specific to arrays. See also:
Zero-based numbering - Wikipedia, the free encyclopedia