This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I dont know the answer to this ... but i can say that ..the concept of first element of an array being 0 (ZERO) is INDIAN !! for the obvious reasons ;-)
Originally posted by Deepika Wadhwa: Hi all, i have a basic confusion.. why does array index start from zero ? is there any specific reasond this ?
There is no reason for it other than maybe it was copied from another language like C/C++ ? In COBOL arrays start at 1. It sometimes catches me out ;-D
You may be right when you say it is copied from C/C++ (which may have copied ASM 68000). In these languages, tab[i] refers to a memory adress situated at tab+i*sizeof(tab elements). So it is easier to refer to 0 as being the first element, otherwise it would have needed one more arithmetic operation: tab+(i-1)*sizeof(tab elements). Any other ideas? W.
Yeah, Wilfred is spot on. The reasons for array initialisation at 0 are very low level memory address type stuff, and indeed, low level logic dictates starting at 0, so there is an (uneccessary??) overhead in manipulating this default value for the purposes of our code.
Its not what you do, its the way you say you've done it.