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

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

问题描述

为什么数组中的索引在 C 中从 0 开始而不是从 1 开始?

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

推荐答案

在 C 中,数组的名称本质上是一个指针 [但请参阅注释],对内存位置的引用,因此表达式 array[n] 指的是远离起始元素的内存位置 n 个元素.这意味着索引用作偏移量.数组的第一个元素正好包含在数组引用的内存位置(0 个元素之外),所以它应该表示为 array[0].

In C, the name of an array is essentially a pointer [but see the comments], 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].

更多信息:

http://developeronline.blogspot.com/2008/04/why-array-index-should-start-from-0.html

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

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