answersLogoWhite

0


Best Answer

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.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why the index of an array be a positive number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the index number of the last element of an array with 9 elements?

(array.length - 1) will find the index of the last element in an array (or -1 if the array is empty).


Full defecation of array?

Full representation of an array begins from the index 0 and ends at n-1 where n is the number of variables of the array.


What are the main features of arrays. How are arrays used and created?

AnswerWhat is an array: In programming languages, an array is a way of storing several items (such as integers). These items must have the same type (only integers, only strings, ...) because an array can't store different items. Every item in an array has a number so the programmer can get the item by using that number. This number is called the index. In some programming languages, the first item has index 0, the second item has index 1 and so on. But in some languages, the first item has index 1 (and then 2, 3, ...).


Index of an element in array?

An array is a group of related elements, with a common variable name. The index is a number that indicates the position of an element within an array: the 1st. element, the 2nd. element, etc. (many languages start counting at zero).


How do you declare an array on Pascal?

type array-identifier = array[index-type] of element-type; array-identifier : the name of your array index-type : any scaler except real element-type : the type of element The index type defines the range of indices and thus the number of elements to allocate. For example, [0..41] will allocate 42 elements indexed from 0 to 41, thus creating a zero-based array. If you require a one-based array, use [1..42] instead. Regardless of the range of indices, the first element is always at the lowest address of the array (the compiler will convert your index range into a zero-based range automatically). The element-type determines the length of each element in the array. Multiplying the element length by the number of elements gives the total amount of memory allocated to the array.

Related questions

How can you get position of number from given some number by using array in c language?

Traverse the array from index 0 until you find the number. Return the index of that number.


What is the index number of the last element of an array with 9 elements?

(array.length - 1) will find the index of the last element in an array (or -1 if the array is empty).


Why the array is starting from zero?

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)


Full defecation of array?

Full representation of an array begins from the index 0 and ends at n-1 where n is the number of variables of the array.


Undefined index in PHP?

Please focus on the line number before the line of the error. There must be an array, with some issues with the index.


What is difference between key and index in php arrays?

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).


What are the main features of arrays. How are arrays used and created?

AnswerWhat is an array: In programming languages, an array is a way of storing several items (such as integers). These items must have the same type (only integers, only strings, ...) because an array can't store different items. Every item in an array has a number so the programmer can get the item by using that number. This number is called the index. In some programming languages, the first item has index 0, the second item has index 1 and so on. But in some languages, the first item has index 1 (and then 2, 3, ...).


What is the Program to find the largest element in an array and position occurrence?

#include<stdio.h> #include<conio.h> main() { int a[100]; int n,largest,index,position; printf("enter the number of elements in the array"); scanf("%d",&n); printf("enter %d elements",n); for(index=0;index<n;index++) scanf("%d",&a[index]); largest=a[0]; position=0; for(index=1;index<n;index++) if(a[index]>largest) { largest=a[index]; position=index; } printf("largest element in the array is %d\n",largest); printf("largets element's position in the array is %d\n",position+1); getch(); }


Index of an element in array?

An array is a group of related elements, with a common variable name. The index is a number that indicates the position of an element within an array: the 1st. element, the 2nd. element, etc. (many languages start counting at zero).


How do you declare an array on Pascal?

type array-identifier = array[index-type] of element-type; array-identifier : the name of your array index-type : any scaler except real element-type : the type of element The index type defines the range of indices and thus the number of elements to allocate. For example, [0..41] will allocate 42 elements indexed from 0 to 41, thus creating a zero-based array. If you require a one-based array, use [1..42] instead. Regardless of the range of indices, the first element is always at the lowest address of the array (the compiler will convert your index range into a zero-based range automatically). The element-type determines the length of each element in the array. Multiplying the element length by the number of elements gives the total amount of memory allocated to the array.


Find index number of an given array?

For instance, you have array of type int with a name myArray, and you do not know size of the array. You can use following statement to get it:int arraySize = myArray/myArray[0];arraySize gives you number of elements in myArray.


What is the 8085A microprocessor code for finding the largest number?

The processor makes no difference in C programming -- the compiler will generate the appropriate instructions for you. To find the largest number in a sequence of numbers, store the numbers in an array. Then invoke the following function, passing the array and its length: unsigned largest (double* num_array, unsigned size) { if (!num_array !size) return size; unsigned max = 0; unsigned index; for (index=1; index<size; ++index) if (num_array[index]>num_array[max]) max = index; return max; } The return value holds the index of the largest value in the array.