这个规则并不是在所有计算机语言上通行的,例如Matlab上就是从1开始。

这个规则是从内存寻址设计上继承来的,因为在如100个元素的数组对应的内存单元中,从内存地址位0开始到内存地址为99,总共记录99个数据就好;而若是从1开始则需要到100。

1 //代码如下
2 #include <stdio.h>
3 
4 int main()
5 {
6          int a[] = {2, 5, 6};
7          printf("第3个元素为%i\n", a[2]);  
8          Return 0; 
9 }

 

posted on 2017-01-01 17:46  历久弥坚0820  阅读(2000)  评论(0编辑  收藏  举报