为什么在Java数组索引从0开始? [英] Why is array indexing in Java start with 0?

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

问题描述

为什么数组索引 0像Java编程语言完成的,而不是1?
我完全对Java任何解释表示欢迎。

Why is array indexing done with 0 and not with 1 in programming languages like Java ? I am totally new to java any explanation is welcomed.

推荐答案

Java使用从零开始的索引,因为C使用从零开始的索引。 C使用从零开始的索引,因为数组索引无非就是内存所抵消,所以数组的第一个元素是它已经指向内存中, *(数组+ 0)

Java uses zero-based indexing because c uses zero-based indexing. C uses zero-based indexing because an array index is nothing more than a memory offset, so the first element of an array is at the memory it's already pointing to, *(array+0).

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

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