Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do prevailing programming languages like C use array starting from 0? [duplicate]

Possible Duplicate:
Why does the indexing start with zero in 'C'?

Why do prevailing programming languages like C use array starting from 0? I know some programming languages like PASCAL have arrays starting from 1. Are there any good reasons for doing so? Or is it merely a historical reason?

like image 830
Strin Avatar asked Dec 19 '25 23:12

Strin


1 Answers

Because you access array elements by offset relative to the beginning of the array.

First element is at offset 0.

Later more complex array data structures appeared (such as SAFEARRAY) that allowed arbitrary lower bound.

like image 131
GSerg Avatar answered Dec 24 '25 12:12

GSerg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!