Why is array indexing in Java start with 0?

前端 未结 6 844
深忆病人
深忆病人 2020-12-01 15:06

Why is array indexing done with 0 and not with 1 in programming languages like Java ? I am totally new to java any explanation is welcomed.

6条回答
  •  清歌不尽
    2020-12-01 15:59

    To expand upon @Kevin's answer, I take this quote from an answer on Programmers.SE:

    The index in an array is not really an index. It is simply an offset that is the distance from the start of the array. The first element is at the start of the array so there is no distance. Therefore the offset is 0.

    Further, if you want to learn more about how different languages do their array indexing, then look at this exhaustive list on Wikipedia.

提交回复
热议问题