Why does the indexing start with zero in 'C'?

前端 未结 16 2477
执念已碎
执念已碎 2020-11-22 16:22

Why does the indexing in an array start with zero in C and not with 1?

16条回答
  •  攒了一身酷
    2020-11-22 16:43

    The technical reason might derive from the fact that the pointer to a memory location of an array is the contents of the first element of the array. If you declare the pointer with an index of one, programs would normally add that value of one to the pointer to access the content which is not what you want, of course.

提交回复
热议问题