AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



java-array: Why array index starts with 0 ?

I want to know a good reason of why array index start with zero always. Please explain properly.

java x 211
array x 12
Posted On : 2014-01-03 16:17:51.0
profile Saksham Kumar - anyforum.in Saksham Kumar
73433939091
up-rate
6
down-rate

Answers


In order to provide modulo (%) facilities as far as mathematics and logic is main concern. for instance, if we have no. of employees in our list say 1545 and if we want to accommodate it within small and effective range then by using % we can do it easily. we can arrange it in the range within Array with maximum index 14 (0,1,2,.....14). And 0,15,30,45......1545 will belongs to same category say index no 0. Think if 0 is not included into index then where we would store 0,15,30,45....1530,1545 . From a technical standpoint, you need to understand that an array is basically just the starting address of a chunk of memory. The "index" of the array is actually an address offset. So the value at the 0th position would be stored at the address of the array plus zero. The value at the 1st position would be stored at the address plus one, and so on.

Posted On : 2014-01-03 16:33:02
Satisfied : 2 Yes  0 No
profile Garima Gupta - anyforum.in Garima Gupta
596129558962
Reply This Thread
up-rate
5
down-rate

Also, we find answer to this question in the world of C language:
The address of an element in an array = (arrayName + indexOfElementInArray).
Such an element is referred to as arrayName[indexOfElementInArray]; and equally well as indexOfElementInArray[arrayName].

Posted On : 2015-03-25 16:55:27
Satisfied : 0 Yes  0 No
profile Rishi Raj - anyforum.in Rishi Raj
040
Reply This Thread
up-rate
1
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in