为什么数组索引是基于大多数编程语言为零? [英] Why array indexes are zero based in most programming languages?
本文介绍了为什么数组索引是基于大多数编程语言为零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
C ++,C#,C,D,Java的,......是从零开始的。
Matlab是我唯一知道的语言,从1开始。
解决方案
阵列基于C和C零
++作为重present的从项目列表的开始偏移。
这两条线都在C相同的结果。
anArray [3] = 4;
*(anArray +3)= 4;
首先是标准索引第二个采用指针增加了三到ID,然后dereffrences它。这是相同的索引器。
C++, C#, C, D, Java,... are zero based.
Matlab is the only language I know that begin at 1.
解决方案
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.
这篇关于为什么数组索引是基于大多数编程语言为零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文