why array start with 0th location
why array start with 0th location
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Feb 18, 2013, 8:56 AM
In C array elements are laid out one after the other in memory and are typically accessed using pointers.
If the first element always has a subscript of zero, then this means that there is no need to deduct the subscript of the first element when working out the offset into the array at which a particular element is stored or to store the starting subscript itself. This clearly improves the efficiency of the underlying implementation.
In C#, arrays are stored and accessed in a similar fashion though the underlying use of pointers is hidden from the programmer except in the case of 'unsafe' code.
brunda kPosted Feb 18, 2013, 7:40 AM