+ 2

Who can answer me on a question? "Why arrays start with '0'?" By technical meaning. Why computer does it?

7th Apr 2016, 4:00 PM
Terekhov Dmitry
Terekhov Dmitry - avatar
3 Réponses
+ 9
The array is basically a pointer to a memory location, and so the expression array[n] points to a memory location which is n-elements away from the first 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 points to (0 elements away), so it should always be referred as array[0].
12th May 2016, 12:43 PM
James Flanders
+ 2
this is because it is intentional as a[0]'s address is a when we write / output a string we can directly use a if first element was considered as a[1] then we would have to write a + 1 to access array which would be not that simple
17th Jul 2016, 3:22 PM
manish rawat
manish rawat - avatar
0
I will give you an example ==== int array [5]; // it's the same with int *array; array=(int *)malloc (5*sizeof (int)); ==== this is how your compiler see your code you arrays= special form of pointers
28th Dec 2016, 11:32 PM
dimitris kuriakopoulos
dimitris kuriakopoulos - avatar