Why does the index of an array start at zero instead of one? Was it simply the preference of the creator of the language?
Why does the index of an array start at zero instead of one? Was it simply the preference of the creator of the language?
The array name is a pointer is disguise, it therefore has an address. The index is used to offset from that address... an offset of zero means you're at the beginning.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
>>The array name is a pointer is disguise, it therefore has an address.
Close enough :-)
>>Why does the index of an array start at zero instead of one?
Think of it like this, each index is the number of items from the beginning using an offset
If indices started with 1 then how would you get a hold of the beginning? Since *(array + 1) is one item past the beginning you have to use an offset of 0 insteadCode:*(array + i)
The reason C is like this is because it's faster and easier to write compilers using the offset instead of using something weird like starting with 1 because computers think in offsets, they start with 0 instead of 1 :-)Code:*(array + 0)
*Cela*