Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: why the array index has to start at 0??

by davorg (Chancellor)
on Jun 23, 2009 at 10:10 UTC ( #773937=note: print w/ replies, xml ) Need Help??


in reply to why the array index has to start at 0??

I suppose the "technical reason" is that it's something we inherited from C. And in C, an array index is actually an offset from the start of the array. The first element is therefore at index zero as it's offset zero elements from the start of the array.

There's no real technical reason why it should still be implemented that way. But generations of programmers expect it to work like that.

Update: Please do not be tempted to use $[ to change the index base. Really, don't do it. Just forget it exists. If you use it you'll just create a maintenance nightmare for the people who look after your program after you.

--

See the Copyright notice on my home node.

Perl training courses


Comment on Re: why the array index has to start at 0??

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://773937]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (18)
As of 2014-07-29 16:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (223 votes), past polls