为什么从'0'数组索引开始

编程入门 行业动态 更新时间:2024-10-23 08:27:14
本文介绍了为什么从'0'数组索引开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对C / C ++数组的一个问题。

I have a question on C/C++ arrays.

为什么数组的索引从开始'0'不是从'1'?

Why does the index of the arrays start from '0' not from '1'?

有任何数学的原因是什么?

Is there any mathematical reason for that?

推荐答案

在大多数编程语言,任何数组的名字是一个指针,它只不过是一个内存位置的引用,因此前pression阵列[n]的指向的存储器位置是从第一元件正元件程。这意味着该索引用作偏移。该阵列的第一个元素是恰好包含在阵列指向(0元件的距离),因此它应该始终称为阵列的存储器位置[0]

In most programming language, the name of any array is a pointer, which is nothing but a reference to a memory location, and so the expression array[n] points to a memory location which is n-elements away from the first 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 points to (0 elements away), so it should always be referred as array[0].

在进行[I]也可在[A + I]被表示为*(A + I)读为值,所以它总是起始于零。

a[i] can also be read as value at [a+i] which is denoted as *(a+i) , so it always starts at zero.

更多推荐

为什么从'0'数组索引开始

本文发布于:2023-11-29 16:41:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646973.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   索引

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!