为什么索引与'C'从零开始? [英] Why does the indexing start with zero in 'C'?

查看:187
本文介绍了为什么索引与'C'从零开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在数组索引用C从零开始而不是1?

Why does the indexing in an array start with zero in C and not with 1?

推荐答案

在C中,数组名本质上是一个指针,一个内存位置的引用,因此前pression阵列[N]指到存储位置正元件从起始元件远。这意味着该索引用作偏移。该阵列的第一个元素是正好包含在该阵列指的存储器位置(0元件的距离),因此它应该被表示为阵列[0]

In C, the name of an array is essentially a pointer, a reference to a memory location, and so the expression array[n] refers to a memory location n-elements away from the starting element. This means that the index is used as an offset. The first element of the array is exactly contained in the memory location that array refers (0 elements away), so it should be denoted as array[0].

了解更多信息:

<一个href=\"http://developeronline.blogspot.com/2008/04/why-array-index-should-start-from-0.html\">http://developeronline.blogspot.com/2008/04/why-array-index-should-start-from-0.html

这篇关于为什么索引与'C'从零开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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