--- title: 2023-02-21 星期二 slug: diary-2023-02-21 date: 2023-02-21 author: KazooTTT tags: - 日记 published: true description: >- 在2023年2月21日的内容中,讨论了数组元素索引为何从0开始编号的问题。根据地址计算公式,索引实际上代表了内存地址的偏移量,首个元素的地址偏移量为0,因此索引从0开始是合理的。文章中还提供了一张图示,进一步解释了这一概念。 rinId: 23 toAstro: false category: 日记-2023-02 --- # 2023-02-21 星期二 ## 数组 [4.1. 数组(Array) - Hello 算法 (hello-algo.com)](https://www.hello-algo.com/chapter_array_and_linkedlist/array/#411) **为什么数组元素索引从 0 开始编号?**  根据地址计算公式,**索引本质上表示的是内存地址偏移量**,首个元素的地址偏移量是  0 ,那么索引是  0  也就很自然了。 ![Pasted image 20230221221853](https://pictures.kazoottt.top/2024/04/20240407-170214c87b99ed229900334e27d6db5d.png)