Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2015-02-27 16:24 GMT
Find Nodes?
    Voting Booth?

    On my keyboard, Caps lock is:

    Results (449 votes), past polls