I was trying to work with array in c language and wondered that the base index of array does not start with other than zero like it doesn’t start with 1, 2, 3… I just want to know the concept behind.
“Why the base index of array is zero in c language” As I am a beginner in c programming language and I have more doubts about C issues, I will definitely post and look for more c programming questions and answers in this community forum. Hope I will get genuine replies to my programming query.
The only reason the base index of array is zero in most languages to simplify the mathematical calculations related to array.
For example:- If you want to iterate over an array and you want to access first element after the last element, then you can do so by simply index = (index+1)(Array_size).
But if base index of array is 1 then we have to do index = index(Array_size)+1
You can get a detailed answer to your question on quora
The address of any array location N is calculated as follows:(let’s assume integer array)
address of Nth index element = baseAddress + (N * size_of_integer)
The name of the array itself gives us the base address of the array(address of first element of array). Hence, in most programming languages If we don’t start indexing from 0 then we won’t be able to access first element of the array.
Because in most languages arrays are just items being put after one another in memory. The array index is then the offset from the start of the array. The first element has no offset, so it’s index is 0.