为什么在大多数编程语言中数组索引都是基于零的? [英] Why array indexes are zero based in most programming languages?

查看:21
本文介绍了为什么在大多数编程语言中数组索引都是基于零的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C++、C#、C、D、Java ……都是从零开始的.

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

Matlab 是我所知道的唯一从 1 开始的语言.

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

推荐答案

数组在 c 和 c++ 中是基于零的,表示从项目列表的开头开始的偏移量.

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

这两行在 c 中有相同的结果.

These two lines have identical result in c.

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

第一个是标准索引器,第二个是将指针添加到 id 上,然后取消引用它.与索引器相同.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆