66.4k views
2 votes
Array indices must be positive integers...

A) True
B) False

1 Answer

5 votes

Final answer:

The statement that array indices must be positive integers is false. While many programming languages use 0-based indexing with positive integers, some languages like Python also support negative indices for reverse traversal of arrays.

Step-by-step explanation:

The statement "Array indices must be positive integers" is false. In computer programming, arrays are used to store multiple values in a single variable, where each value is identified by an index. While it is commonly true that array indices start at 0 and increase with positive integers, certain programming languages and specific applications might use different schemes. For example, in some programming languages like Python, negative indices are used to access elements from the end of the array.

In most programming languages like C, Java, and JavaScript, the index of the first element in the array is 0, not 1. This means that for an array arr with 10 elements, the indices would range from 0 to 9. Negative indexing is not supported in these languages, and using a negative index would typically result in an error.

However, as mentioned earlier, Python supports negative indices. In Python, an index of -1 would correspond to the last element of the array, -2 to the second-last element, and so on. Despite this, the indices used must still be whole numbers and cannot be fractional or decimal values.

User Rohan Kangale
by
9.6k points