why array index always starts with 0?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Selesteena

    why array index always starts with 0?

    just i want to know the reason....
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Array indexes start with 0 because the name of the array is the address of the first element in the array.

    So, the array name + 1 should be the second element.
    That will only work if array name + 0 is the first element.

    So then, array[0] is the first element and array[1] is the second element.

    Comment

    • prafi pancholi

      #3
      because array pointer has set by default as 0 position and if any data put in to the array that the pointer automatically point that element as 0 addressed and then next it will increase by 1.
      for ex. ptr=0(first value)
      ptr=ptr+1

      Comment

      Working...