+ 24
Why array starts at 0?
I was looking for good explanation of this question and best explanation I found is : much easier to create multidimensional arrays if indices start at 0, 'a[i*n+j]' vs 'a[(i-1)*n+j]' is this the reason or there is other reason as well.
9 Respuestas
+ 10
Memory wise the index provided is an offset for the start of the array ( array pointer ). If you have an array of integers, you could access the integer at array[2] by taking the memory adress of array[0] and adding sizeof(int)*2 to it. This is how an array is beeing stored in your memory.
So array[0] means starting adress of the array with 0 offset ;)
+ 16
@Ace I do searched on google, stack overflow. The answer I got was easier to explain others but I asked for other reason that maybe in a book.
+ 12
@Kuba Matlab maybe Fortan also. This was implemented after C era.
+ 6
R starts them from 1 :)
+ 5
it is a scheme called zero based indexing,in some languages they start with one
+ 4
My first language was c..
Sometimes at night i still wake up from a nightmare where a dereferenced pointer, pointing at a pointer is doing a call by value..
+ 4
@siebenWinkel I ever nightmare about .toString() !
+ 2
I like siebenWinkels answer better, but I learnt it as: although in high level programming languages we write code in letters, digits and other characters, this gets turned into binary, and typically datatypes of programming languages have a set number of bytes that they get converted to so there is a limit on how many different values there are. Since it doesn't make logical sense to find the 0th position of an array, but the type an index is defined as contains a zero, you can maximise the potential size of arrays by starting at zero
0
Lol. U get upvote for ask like this. No body say try search on google. Not like when I asking a simple question.