answersLogoWhite

0


Best Answer

Since arrays in C are zero based, the allowed subscript range is 0 - 99 (gives 100 values). Always remember to subtract 1 from the high range (in this case 100) to get the last subscript maximum value.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: If an array has a 100 elements what is the allowable range of subscripts?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the difference between subscript and subscripted variable in c plus plus?

Subscripts are used to identify the elements in an array, where the first element has subscript 0. Thus an array of n elements has subscripts in the range 0 to n-1. Each element may itself be an array, thus allowing multi-dimensional arrays. The subscript may be a constant or a variable. However, when declaring a static array, the subscript must be a constant. Constants include literal constants as well as named constants. A subscripted variable is simply an array or a datatype that can be divided into an array. For instance, a 32-bit int can be treated just as if it were an array of two 16-bit shorts or four 1-byte chars. Thus in the 32-bit int array, int i[10], i is a subscripted variable where i[0] is the first integer and i[9] is the last. If we then say char*c=&i, c would allow us to treat i as if it were a subscripted variable with 40 char elements (c[0] to c[39]).


How do you find missing numbers in a array with elements below its size?

Please rephrase your question. An array usually has a fixed size and I don't recall ever having to "go below its size". This implies that the missing elements are not within the range of the array.


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.


Difference between integer array and character array?

Arrays are basic structures wherein one or more elements exist "side by side" and are of the same "type". An "integer" array is an array whose elements are all of an integer type which has no fractional component. A "character" array is an array which contains nothing but character types. A "floating point" array contains elements that have both an integer and fractional portion. Simply put, they are arrays of particular types.


What are subscripts in c language?

Subscripts are used when accessing arrays. An array is a contiguous block of memory containing two or more elements of the same type. Since each element is the same length, it is trivial to work out the offset address of one element relative to another using a zero-based index. For any type T, the type T[n] is an array of Ts with indices in the range 0 to n-1. We can also create arrays at runtime by allocating sufficient memory on the heap for the given type: void f(int n) { if (n<1) return; // cannot allocate 0 elements! int* ptr = malloc (n * sizeof(int)); // allocate memory for n integers if (ptr!=0) return; // ensure memory was allocated! ptr[0] = 42; // use subscript operator to assign a value to the first element // assign to other elements... // use array... free (ptr); // release memory as soon as we're finished with it }

Related questions

What is the difference between subscript and subscripted variable in c plus plus?

Subscripts are used to identify the elements in an array, where the first element has subscript 0. Thus an array of n elements has subscripts in the range 0 to n-1. Each element may itself be an array, thus allowing multi-dimensional arrays. The subscript may be a constant or a variable. However, when declaring a static array, the subscript must be a constant. Constants include literal constants as well as named constants. A subscripted variable is simply an array or a datatype that can be divided into an array. For instance, a 32-bit int can be treated just as if it were an array of two 16-bit shorts or four 1-byte chars. Thus in the 32-bit int array, int i[10], i is a subscripted variable where i[0] is the first integer and i[9] is the last. If we then say char*c=&i, c would allow us to treat i as if it were a subscripted variable with 40 char elements (c[0] to c[39]).


How do you find missing numbers in a array with elements below its size?

Please rephrase your question. An array usually has a fixed size and I don't recall ever having to "go below its size". This implies that the missing elements are not within the range of the array.


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.


What is the index of the third element of a vector is C plus plus?

Index 2. All subscripts are zero-based in C++ because the first element (at index 0) is offset 0 elements from the first element while the second (index 1) is offset 1 element from the start, and so on. Given a vector of n elements, the valid subscripts are in the range 0 through n-1.


Difference between integer array and character array?

Arrays are basic structures wherein one or more elements exist "side by side" and are of the same "type". An "integer" array is an array whose elements are all of an integer type which has no fractional component. A "character" array is an array which contains nothing but character types. A "floating point" array contains elements that have both an integer and fractional portion. Simply put, they are arrays of particular types.


What are subscripts in c language?

Subscripts are used when accessing arrays. An array is a contiguous block of memory containing two or more elements of the same type. Since each element is the same length, it is trivial to work out the offset address of one element relative to another using a zero-based index. For any type T, the type T[n] is an array of Ts with indices in the range 0 to n-1. We can also create arrays at runtime by allocating sufficient memory on the heap for the given type: void f(int n) { if (n<1) return; // cannot allocate 0 elements! int* ptr = malloc (n * sizeof(int)); // allocate memory for n integers if (ptr!=0) return; // ensure memory was allocated! ptr[0] = 42; // use subscript operator to assign a value to the first element // assign to other elements... // use array... free (ptr); // release memory as soon as we're finished with it }


What is an array and what does index mean in an array in c?

An array is an aggregate of elements, where memory is allocated to accommodate a given number of elements of a given type. The name of the array serves as a reference to the first element of the array. Unlike ordinary (non-array) variables, all the other elements of an array have no name; they are anonymous. However, all elements of an array have identity (they have an address) so if we know the address of an element within an array we can easily refer to it by that address. Given that each element is of the same type and therefore the same size (in bytes), we can easily calculate the address of each element offset from the start of the array. That is, the nth element of an array A of type T will be found at address A + sizeof(T) * (n-1). Although we are free to use "pointer arithmetic" like this to calculate the individual addresses of each element, C provides us with a much more convenient notation called the array suffix operator. The array suffix operator applies to pointer variables only. Fortunately, all arrays implicitly convert to a pointer at the slightest provocation so we don't have to do anything special to use them. The operator is denoted using square brackets [] such that for an array A we can refer to its nth element as A[n-1]. Given that A is of type T, the compiler has enough information to generate the required pointer arithmetic for us: A + sizeof(T) * (n-1). Note that array indices are in the range 0 to n-1 for an array of n elements. Attempting to access elements outwith this range has undefined behaviour, so it is important that we take steps to ensure all indices are kept within the bounds of the array. For fixed-length arrays, we can simply use a constant to store the array length, but for variable-length arrays we must keep track of the length using a variable. To range-check a given index against a given length, n, the index must be in the closed range [0:n-1]. However, array index ranges are often denoted using half-closed notation, [0:n), which essentially means 0 <= index < n.


Can you change the size of an array dynamically in Java?

No, you can't change the size of an array dynamically. If you are needing to change the size of an array dynamically use an ArrayList, LinkedList, ConcurrrentHashMap, or another class that meets your needs.


What is the most commonly used data structure?

Vectors (variable-length arrays) are the most commonly used data structure because a vector has the lowest memory overhead of any data container with the exception of fixed-length arrays (the second most-used container). All elements of a vector (and an array) must be of the same type and therefore of the same length, and are allocated in contiguous memory. Each element is identified by a subscript (a zero-based offset index) such that an array of n elements has subscripts in the range 0 to n-1. Subscripting makes it possible to perform bi-directional traversal as well as random-access in constant-time.


Program in c plus plus to delete an element in sorted array?

If the array is dynamic then use a vector instead of an array. You can then use the vector::erase() function to delete an element or a range of elements. Remember that if the vector contains pointers to unshared memory, then you must release the pointer before erasing the element containing that pointer. If the array is static then you cannot delete elements. The assumption with static arrays is that you will neither add nor delete, you will only modify existing elements. However, you can emulate a deletion by shunting elements to the left, and keeping track of how many used elements there are (which must always be less than or equal to the upper bound plus one). Again, if the array contains pointers to unshared memory, you must release the pointer before shunting elements. You can also do the same thing with dynamic C-style arrays, but once you've shunted elements to the left you can reallocate the array with the new size to physically delete the final element.


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 will you Write a c program to find the kth smallest element in an array in c?

//This is for kth largest element. (So this is for n-k smallest element) //Sudipta Kundu [Wipro Technologies] #include <stdio.h> //Input: array with index range [first, last) //Output: new index of the pivot. An element in the middle is chosen to be a pivot. Then the array's elements are //placed in such way that all elements <= pivot are to the left and all elements >= pivot are to the right. int positionPivot(int* array, int first, int last); //Input: array with index range [first, last) and integer K (first <= K < last) //Output: array whose Kth element (i.e. array[K]) has the "correct" position. More precisely, //array[first ... K - 1] <= array[K] <= array[K + 1 ... last - 1] void positionKthElement(int* array, int first, int last, int k); int main() { int array[] = {7,1,8,3,1,9,4,8}; int i; for (i = 0; i < 8; i++) { positionKthElement(array, 0, sizeof(array) / sizeof(array[0]),i); printf("%d is at position %d\n", array[i], i); } return 0; } int positionPivot(int* array, int first, int last) { if (first last) return first; int tmp = (first + last) / 2; int pivot = array[tmp]; int movingUp = first + 1; int movingDown = last - 1; array[tmp] = array[first]; array[first] = pivot; while (movingUp <= movingDown) { while (movingUp <= movingDown && array[movingUp] < pivot) ++movingUp; while (pivot < array[movingDown]) --movingDown; if (movingUp <= movingDown) { tmp = array[movingUp]; array[movingUp] = array[movingDown]; array[movingDown] = tmp; ++movingUp; --movingDown; } } array[first] = array[movingDown]; array[movingDown] = pivot; return movingDown; } void positionKthElement(int* array, int first, int last, int k) { int index; while ((index = positionPivot(array, first, last)) != k) { if (k < index) last = index; else first = index + 1; } }