0

Why do arrays start from 0?

Why do arrays start from 0? It is so confusing and hard to figure out.

31st May 2019, 11:21 AM
Ioan
Ioan - avatar
3 ответов
+ 2
Ioan hi, we generally start array indexing from 0 as moat programming is used this index you can start with indexing 1 too some language like R has Starr array index with 1 nothing being so big in this Refer this link for moat suitable answer to your query https://developerinsider.co/why-does-the-indexing-of-array-start-with-zero-in-c/ Have these 🍎 🍎 🍎 🍎 🍎
31st May 2019, 11:36 AM
DishaAhuja
DishaAhuja - avatar
+ 3
If you look at a classic C string like char str[] = {"Hello"}, "str" is a pointer to the first element of the char array and you can move the pointer to the next char by adding 1. *(str+1) points to the second character, 'e'. It's equivalent to str[1]. Same with *(str+2) = str[2] etc. Hence the first element is str[0] which is equivalent to *(str+0) (or simply *str). If you think about it, it would be highly confusing if array indices started with 1. You'd always have to consider that str[n] means something else than *(str+n).
31st May 2019, 11:49 AM
Anna
Anna - avatar
+ 1
It's conventional
31st May 2019, 12:21 PM
Fabien First
Fabien First - avatar