Pathologically Eclectic Rubbish Lister PerlMonks

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

by Crian (Chaplain)
 on Jun 23, 2009 at 10:17 UTC ( #773941=note: print w/replies, xml ) Need Help??

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

Zero is the first natural number, so it seems to be natural, to start the index with it.

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

Replies are listed 'Best First'.
Re^2: why the array index has to start at 0??
by Anonymous Monk on Oct 13, 2013 at 06:41 UTC

'0' does not come in natural no. It comes in whole no. Natural no. starts with '1'

Dave

From Wikipedia Natural_number as well:

There is no universal agreement about whether to include zero in the set of natural numbers: some define the natural numbers to be the positive integers {1, 2, 3, ...}, while for others the term designates the non-negative integers {0, 1, 2, 3, ...}. The former definition is the traditional one, with the latter definition having first appeared in the 19th century.
Re^2: why the array index has to start at 0??
by Anonymous Monk on Dec 21, 2012 at 08:10 UTC

zero is not a natural number. its a whole no.!!!!!!!!!

No, it's a hole no.!

Re^2: why the array index has to start at 0??
by targetsmart (Curate) on Jun 23, 2009 at 10:27 UTC
IMO it makes much sense for the array to have the first index at 1.
we never call first as "0", we always call first as '1'. so this lead to this thinking.

Vivek
-- 'I' am not the body, 'I' am the 'soul', which has no beginning or no end, no attachment or no aversion, nothing to attain or lose.

It might make sense to you, but chances are that it won't for the maintainers of your code. Arrays in most languages I know start at index 0, I am not sure going against such a common characteristic is such a good idea.

we never call first as "0", we always call first as '1'. so this lead to this thinking.

Really?

• The first km my car drove was km 0000000 on the odometer.
• The first inch on a ruler is inch zero.
• The first century AD was century zero.
• The first raffle ticket on the spool is xxx000.

It's not exactly a foreign concept.

The first century AD was century zero.

I thought the first century A.D. was century 1, the first year of which was year 1 A.D. (with the year before being 1 B.C.), the concept of "zero" not percolating into European thought until some non-zero number of centuries later. Which is why, twenty centuries later, we are stuck with 2001 being the first year of the twenty-first century.

On your first birthday, did you turn one or two? :D

This is the "How is babby formed??" of programming questions.

Please tell me who in India taught you how to code, or who otherwise put the idea in your head that array indecies (or anything else programming-wise) should begin with 1, so I can punch them in the neck.

'How is babby formed' features the idiotic ramblings of semi-literate native English speakers. targetsmart has not shown himself to be an idiot.

Why arrays start at index 0 rather than 1 is a good question. It shows that he is questioning the foundations of the language as he learns, and seeking to understand things at a fundamental level.

Basic, "obvious" questions that are so fundamental as to be invisible to most are the type of questions that bring real understanding and advancement.

It is sad to see such rudeness on this site. It is even worse to see racist and ad hominem attacks here.

P.S. The accepted plural form of "index" is typically "indexes", but "indices" is also acceptable. Finding irony of your use of "indecies" is left as an exercise for the reader.

TGI says moo

Please tell me who in India taught you how to code
Nobody taught me, I did self learning from C .. Perl.

who otherwise put the idea in your head that array indecies (or anything else programming-wise) should begin with 1
It is purely my idea/thought
BTW my idea is not to advocate anyone that start using the array index from 1, just wanted to know why it is that way.

so I can punch them in the neck.
you can't :)

Vivek
-- 'I' am not the body, 'I' am the 'soul', which has no beginning or no end, no attachment or no aversion, nothing to attain or lose.

Create A New User
Node Status?
node history
Node Type: note [id://773941]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2018-06-21 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should cpanminus be part of the standard Perl release?

Results (117 votes). Check out past polls.

Notices?