top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Why array index in C starts from zero?

+1 vote
Why array index in C starts from zero?
posted Sep 29, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

4 Answers

+2 votes

My view (may be wrong)

If you start from 0 you will save memory space as compare to 1 for example you need three bits to represent the 8 numbers (0--7) if numbers are from 1--8 then you need 4 bits....

answer Sep 29, 2014 by Salil Agrawal
Best reason among all the reasons...
0 votes

In C, the name of an array is essentially a pointer, a reference to a memory location, and so the expression array[n] refers to a memory location n-elements away from the starting element. This means that the index is used as an offset. The first element of the array is exactly contained in the memory location that array refers (0 elements away), so it should be denoted as array[0].

Credit- Stackoverflow

answer Sep 29, 2014 by Aarti Jain
0 votes

Index in an array represents the distance of an element from the beginning of the array.
So, a[0] is actually *(a+0) - the element at the 0th distance from the start of the memory region.
If the distance is 1, then you are at one element away from the beginning.

answer Sep 29, 2014 by Ranjith
0 votes
answer Sep 29, 2014 by Arshad Khan
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.