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

前端 未结 16 2515
执念已碎
执念已碎 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:59

    I am from a Java background. I Have presented answer to this question in the diagram below which i have written in a piece of paper which is self explanatory

    Main Steps:

    1. Creating Reference
    2. Instantiation of Array
    3. Allocation of Data to array

    • Also note when array is just instantiated .... Zero is allocated to all the blocks by default until we assign value for it
    • Array starts with zero because first address will be pointing to the reference (i:e - X102+0 in image)

    Note: Blocks shown in the image is memory representation

提交回复
热议问题