Why Do Arrays Start at Zero?

A common point of confusion for new programmers arises when trying to access a item in an array/list/slice/string etc. The “first” item is not located in position 1, but rather it is in position 0, or so it seems. The reason for this is all thanks to the programming language C. But why is C like that? For this we need to understand pointers. A pointer is a variable that stores a memory location holding a value. More specifically it is the beginning position in memory. For example, say we have a string “abcdefg” and using ACSII each character is 1 byte. Lets also say it is stored in memory starting at location 42. I will be using the decimal representation for the sake of simplicity:

[Read More]
array  index