Why do arrays start at zero?
Arrays are series of elements that have the same type, placed in adjacent positions. The elements can be individually used or utilized by attaching and index to a certain specific identifier. An array therefore is a more convenient way of declaring different values of the same type. Like a regular variable, an array must be declared before it is used. In some programs, there can be instances where the array can be visible and accessing its value can be possible. In this case, the values contained in the array can both be read and modified just like any normally existing variable. Arrays can also contain another set of arrays which is formally called multidimensional arrays. This type of array is commonly utilized by programmers to serve as abstraction since the same results can be obtained even with the use of simple arrays. The advantage of using multidimensional arrays is that the depth of each imaginary dimension can be fully remembered. Arrays also function as parameters when the element type of the array is specified and an identifier and a pair of void brackets are available.
One common query about arrays is on why it always starts with zero. Initially speaking, it has strong relation to language design. In most circumstances, the memory location is expressed in relation to the distance from the starting element. Since the first element of the array is exactly contained in the memory location that array refers, then the location is deemed to start at zero. More so, the zero-based array is more natural in the root machine language. The array always starts with zero because it serves as the offset of the element accessed from the address of the first element. Thus, arrays always tend to start at zero.
Leave a Reply