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

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

问题描述

为什么在 Java 等编程语言中数组索引用 0 而不是 1 完成?我对 Java 完全陌生,欢迎任何解释.

解决方案

Java 使用从零开始的索引,因为 c 使用从零开始的索引.C 使用从零开始的索引,因为数组索引只不过是一个内存偏移量,所以数组的第一个元素在它已经指向的内存中,*(array+0).>

另见维基百科的不同语言的数组索引?

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 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).

See also Wikipedia's array indexing in different languages?

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

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