Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by ikegami (Pope)
on Jun 23, 2009 at 15:31 UTC ( #774064=note: print w/replies, xml ) Need Help??


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

It was something to do with boudary checks

If you want to check if a value X is in [0,N) — something that must be done very often — X % N == N will do. If N is a power of two, simpler X >> log(N) would do.

If on the other hand you were using 1-based indexes, you'd have to check if X is in [1,N], and that would require (X-1) % N == (X-1).

Many more operations are simply more natural with 0-based indexes. See Re^3: why the array index has to start at 0?? for some real-life examples.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://774064]
help
Chatterbox?
[Discipulus]: in this ubuntu i'm not able to find resource monitor, graphical mount program.. just office and amazon are exposed!

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2016-12-07 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (125 votes). Check out past polls.