This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on Arrays

 
sanyasirao nali
Greenhorn
Posts: 6
Java Oracle Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why arrays are started with 0(zero) index...?

example: a[5]={23,5,34,23,21}
here a[0]=23,a[1]=5 . . . . . . ,a[4]=21.
here a[] started with a[0] not a[1]......why arrays are starting with 0(zero) index...?



Thankyou in Advance.
 
dennis deems
Ranch Hand
Posts: 808
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An array is not merely a logical structure; it is a contiguous chunk of memory space. What makes using arrays so blindingly fast is that we can get any array element by applying an offset ( the index number ) to the start of the array. To get the first array element, we go to the start of the array and apply an offset of zero. To get the fifth element we go to the start of the array and apply an offset of four.
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why arrays are started with 0(zero) index...?

Arrays in Java start at 0 but not all languages take this approach.
See this thread for an explanation: http://www.coderanch.com/t/384946/java/java/starting-index-array
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic