answersLogoWhite

0

Why the array is starting from zero?

Updated: 8/19/2019
User Avatar

Wiki User

12y ago

Best Answer

By design; it makes the compiler's work easier.

1-based array's addressing-function:

Address (array, index) = Address (array) + (index-1)*Elemsize(array)

0-based array's addressing-function:

Address (array, index) = Address (array) + index*Elemsize (array)

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why the array is starting from zero?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is starting subscripts value for integers arrays?

0. For many (every) languages, for every type of array, the starting subscript is zero.


How do you start array list from 1?

Array indices are zero-based because the first element is at offset zero from the start of the array. There is no such thing as a one-based array in C. Some other languages do allow you to specify the base of an array, but converting a non-zero-based index to a zero-based index adds a runtime overhead to the implementation.


What do array subscripts always have?

Array subscripts always have a zero-based index. In languages that allow an n-based index, the index is simply offset by n elements, so the compiler subtracts n from the given index to obtain the zero-based index. Arrays are always zero-based because the first element of an array is found zero elements from the start of the array.


How do you read data from array?

Use the array suffix operator [] to access the individual elements of an array through a zero-based index.


Why numeric arrays do not end with a '0' in C programming language?

The value zero is a perfectly valid numeric array element in its own right. If we used the value zero to mark the end of a numeric array in the same way we use a null-terminator to mark the end of a string (a character array), we'd have no way of representing the value zero within the array itself. Thus when working with numeric arrays, we must keep track of the array length independently of the array.


What are sparse matrixes?

A sparse matrix is an array with more zero values than non-zero values.


How do you find greatest no using array in java?

Assume that the greatest number is the first element (subscript zero). Compare with each element in the array (starting with subscript one), and every time you find one that is greater than the greatest so far, set your variable "greatest" to this number.


What would the valid subscript values be in a four element array of doubles?

since the array is four elements and array subscripts start at zero, the valid ones would be 0, 1, 2, 3


How do you flip an array without using flip function in PHP?

Use a for-loop starting at the length of the array and go backwards and build up a new array with the values.


Why array index always starts with zero?

Because that's how the language is defined. In C, C++, and many other languages, array indecies start with zero. This is by convention, and it also reflects the fact that, in C and C++, array-index syntax can also be expressed in pointer-offset syntax. The pointer locates the first element of the array, and the offset indicates how many elements to skip. If a is an array name, then the expression a[n] is completely identical to the expression *(a+n), and vice versa.


What are strings in C?

an array of characters, usually terminated by a binary zero (0x00 or \0, not '0')


A character array terminated with the null character is most correctly called what?

zero-terminated string