Array
Why array index is starts with zero[0]?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sanjay SinghRank #779 · 2.9K reputationPosted Jul 19, 2014, 6:19 AM EDT
please visit this link
http://developeronline.blogspot.in/2008/04/why-array-index-should-start-from-0.html
VulpesRank #55 · 29.2K reputationPosted Jul 19, 2014, 7:56 AM EDT
Similarly it began with zero in C++ because it began with zero in C and the former was intended to be (more or less) a superset of the latter.
I don't think Brian Kernighan and Dennis Ritchie actually say in their definitive book on the C language why indexing begins at zero but it's probably because arrays and pointers are closely related in that language and there's no doubt that zero indexing makes pointer arithmetic easier - the first element has a zero offset from the start of the array itself - and thus is easier to implement.
Whilst C# doesn't normally use explicit pointers, when you do use them in 'unsafe' code the advantage of zero based indexing soon becomes apparent.