What is the array subscript starting from 0?

Source: Internet
Author: User

We will feel that the array subscript starting from 0 very annoying, subscript 0 began to represent the first, subscript 1 is the second, is not feel particularly awkward. So why is it starting at 0?

Int[] A=new int[]{1,2,3,4,5};


Here are 5 values, first we assume that the array of 5 address numbers in memory are 1000,1001,1002,1003,1004, assuming it is for convenience of computation.

At the moment we visit a[0], that is, access to address number 1000,


Think of it, 1000 is the first address of the array, that is, the first value that represents the group 1,1000+0 equals 1000, if the logical subscript also starting from 1 is not 1000+1=1001 access to the second address 2 slightly.


This is why the array starts at 0, because a refers to the first address number in the array, starting at 0, and the 1 addresses that are accessed.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.