Yes, but it will cause data corruption and/or abnormal program termination. Don't do it.
Since an array cannot contain a negative number of items, the size of an array must be at least 0. So if you ever tried to retrieve the element at a negative index in an array, it would automatically be understood to be out-of-bounds.
(array.length - 1) will find the index of the last element in an array (or -1 if the array is empty).
Basically, &array[i]; That is, the memory location for an array object with index i. Or, you can do: (array + i);
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.
This is very common exception and name of the exception class tells exactly what kind of problem you have. If you would look into stack trace, which should have been generated too you would be able to find exact place where it happened. The problem is that "Array Index Out Of Bounds". This means that you used index on array which is invalid. That could negative number, because all arrays starts from 0. If you array has N items and you will try to get item with index N or higher you will get this exception too. Only available indexes are from 0 to N - 1, where 0 points to the first item and N - 1 to the last one.
Since an array cannot contain a negative number of items, the size of an array must be at least 0. So if you ever tried to retrieve the element at a negative index in an array, it would automatically be understood to be out-of-bounds.
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)
You cannot do this easily in C programming. Arrays in C always start with index 0. If you must use a negative array index, you can do that by allocating an array, and then pointing to an element within the array. Say you allocate an array 10 ints long, named a; then set b = &a[5]. Then b[-4] = a[1]. However, this is extremely bad programming practice and is almost certain to cause data corruption. Some compilers will treat array indices as unsigned, also, so that when you specify b[-4], the compiler will internally simplify that to b[65532] and your program will crash.
You can access the array-element via index (or subscript), but it is not possible the other way around.
(array.length - 1) will find the index of the last element in an array (or -1 if the array is empty).
A key is the name of a variable in an array ($array["key"]) and the index is the position it's at ($array = ["key" => 0], the index would be 0). Keys and indices are the same if the array is not associative though ($array = [true], the key holding the value true is named 0 and is at index 0).
The negative prefix of "array" would be "non-".
Basically, &array[i]; That is, the memory location for an array object with index i. Or, you can do: (array + i);
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.
For an array of length s, the last element has index s-1.
This is very common exception and name of the exception class tells exactly what kind of problem you have. If you would look into stack trace, which should have been generated too you would be able to find exact place where it happened. The problem is that "Array Index Out Of Bounds". This means that you used index on array which is invalid. That could negative number, because all arrays starts from 0. If you array has N items and you will try to get item with index N or higher you will get this exception too. Only available indexes are from 0 to N - 1, where 0 points to the first item and N - 1 to the last one.
by using index position we can find the particular element in array.