Why array indexes are zero based in most programming languages?

前端 未结 6 880
说谎
说谎 2020-11-29 13:46

C++, C#, C, D, Java,... are zero based.

Matlab is the only language I know that begin at 1.

6条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 13:57

    I guess it has mostly historical reasons, new languages just try to use the existing convention which programmers are familiar with.

    Older languages from which this rule originated were close to the metal, and an index is really the distance from the starting element, hence 0 makes sense for the first element.

提交回复
热议问题