954,224 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Arrays

Hi all,

Out of curiosity, why does an array start with 0 instead of 1? It would cut down of alot of confusion if it did.

Thanks

KimJack
Junior Poster
114 posts since Apr 2006
Reputation Points: 8
Solved Threads: 0
 

You not gone be first asking such a question. If you google in most programmming forums such a question been asked. I do not know the answer but I presume it is from past times of old languages like assembler, pascal etc where programer besides of creating program had to keep an eye on memory management. All computer data are digitally organized(ie in binary) even today 0- 0000, 1-0001, 2 0010, 3-0011...
It is said the C programming language actualy made zero array position widely used. Duno....
If you interested may want to read this document by Edsger W. Dijkstra called Why numbering should start at zero

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 901
 

Just a stab in the dark, but I, too, think it's memory management. An array is represented in memory by a pointer to its first element. The index of the array can indicate the offset from the value of that pointer.

cscgal
The Queen of DaniWeb
Administrator
19,421 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 229
 

Thanks cscgal. That makes alot of sense. Still would be nice if it started at 1 and used 0 as an offset instead.

KimJack
Junior Poster
114 posts since Apr 2006
Reputation Points: 8
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You