+ 2
Who can answer me on a question? "Why arrays start with '0'?" By technical meaning. Why computer does it?
3 Answers
+ 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].
+ 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
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