Why array index in C starts with 0?

The array index in C starts with 0 because in C the name of an array is a pointer, which is a reference to a memory location. Therefore, an expression *(arr + n) or arr[n] locates an element n-locations away from the starting location because the index is used as an offset. Likewise, the first element of the array is exactly contained by the memory location that array refers (0 elements away), so it should be denoted as *(arr + 0) or *(arr) or arr[0].

C programming language has been designed this way, so indexing from 0 is inherent to the language.

However, some languages give user a choice to start index from zero or any other positive integer. For an example, in Fortran, when an array is declared with integer a(10) (an array of 10 integer elements), the index starts from 1 and ends at 10. However, this behavior can be overridden using a statement like, integer a(0:9), declaring an array with indices from 0 to 9.

Hope you have enjoyed reading why array index in C starts with zero? Please do write us if you have any suggestion/comment or come across any error on this page. Thanks for reading!




Get Free Tutorials by Email

About the Author

is the main author for cs-fundamentals.com. He is a software professional (post graduated from BITS-Pilani) and loves writing technical articles on programming and data structures.

Today's Tech News

UK regulator has 'huge concerns' over Uber breachPosted on Wednesday November 22, 2017

A data breach affecting 57 million customers and drivers should not have been concealed, the information commissioner says.

Android phones 'betray' user location to GooglePosted on Wednesday November 22, 2017

The devices send location data back to Google even when location services are switched off.

Budget 2017: Funding for AI, 5G and digital skillsPosted on Wednesday November 22, 2017

The chancellor acknowledged the digital revolution would change the way people lived and worked.

Courtesy BBC News

AD BLOCKER DETECTED!

Advertisements help running this site for free.


To view the content please disable AdBlocker and refresh the page.

×