Why array indexes are zero based in most programming languages?

前端 未结 6 868
说谎
说谎 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 14:00

    Arrays are zero based in c and c++ as the represent the offset from the beginning of the list of the item.

    These two lines have identical result in c.

    anArray[3] = 4;
    *(anArray +3) = 4; 
    

    The first is the standard indexer the second takes the pointer adds three to id and then dereffrences it. Which is the same as the indexer.

提交回复
热议问题