answersLogoWhite

0


Best Answer

Depends on the language. For C, no you don't. You can type blank brackets (int Arr[]) when declaring the array, or you can just use a pointer (int* Arr). Both will allow you to use the variable as an array without having to declare the specific size. Hope this answers your question.

In Java, an array is an object, and one which is dynamically allocated space. The default constructor does not require a size be specified.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

Whether you need to do that or not really depends on the programming language. But usually, the programming language or more precisely the runtime environment needs to reserve some space for the array. It can't just go beyond the end of the array, since other - unrelated - data might be stored there. Resizing an array can either be impossible, or expensive, depending on the programming language. "Expensive" in this sense means that it may take some time to relocate the array somewhere else in memory, i.e., reserve space somewhere else, and copy each array element to the new location. This is what Java does when you increase the size of an "ArrayList" - one type of resizable array in Java - beyond a certain limit.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Is it necessary to give the size of array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Which condition is not necessary in dynamic stack?

in dynamic stack we don't have to initialize the size of array while in static stack we have 2 initialize it ......


What is meant by irregular dimensional array?

An irregular dimensional array is a special type of multi-dimensional array.First we must understand that a multi-dimensional array is just an array of arrays. Each element in the array is, itself, an array of elements.A regular multi-dimensional array will be an array of size n, with each element containing a separate array of size m. That is, each sub-array has the same size.An irregular multi-dimensional array will be a multi-dimensional array in which each sub-array does not contain the same number of elements.Regular array:array[0] = new array{0, 1, 2}array[1] = new array{3, 4, 5}array[2] = new array{6, 7, 8}array[3] = new array{9, 10, 11}This regular array is an array of size 4 in which each sub-array is of size 3.Irregular array:array[0] = new array{0, 1, 2}array[1] = new array{3, 4}array[2] = new array{5, 6, 7}array[3] = new array{8, 9, 10, 11}This irregular array is an array of size 4 in which the size of each sub-array is not the same.


What is sparce array?

sparse array is one which has contents lower than its maximum size, that is the array has free or empty locations....


Why fixed size array is not efficient?

It's not exactly true. Array with fixes size are efficient, but do not work well when you have to resize your array. This actually is the answer for your question. Fixed size arrays are not efficient if you have to change the size. Also you cannot destroy them and release memory used to save the array (for that you have to use operator new).


What is the difference between a fixed size array and a variable size array?

The obvious answer is that one has a constant size while the other does not. More specifically, a fixed-size array is one where the size is known at compile time and does not change at runtime. By contrast, the size of a variable-sized array may or may not be known at compile time but may change at runtime. We often refer to a variable-size array as being a dynamic array, however some people (myself included) incorrectly refer to a fixed-size array as being a static array. The misunderstanding largely comes from the fact that we often refer to the heap (or free store) as being dynamic memory because all dynamic variables are allocated there (including variable-size arrays). But the term dynamic array does not refer to the memory, it refers to the dynamic -- as in changeable -- nature of the array itself. By contrast, a fixed-size array is only deemed static if it is statically allocated, in which case it will be allocated in the program's data segment along with all other static variables, global variables and constants. But a local fixed-size array is allocated on the program's stack and is therefore, by definition, non-static. Moreover, you can allocate a fixed-size array on the heap!

Related questions

Sample program of single-dimentional array?

#include "stdio.h" #define SIZE 100; void main() { int array[SIZE], i, size; printf("\nEnter the Size off Array :- "); scanf("%d", &size); printf("\nEnter the Elements of Array :- ")' for(i = 0; i < size; i++) scanf("%d", &array[i]; printf("\nThe Elements of entered Array :- "); for(i = 0; i < size; i++) printf("%7d", array[i]); }


Is there a way to use a variable to declare the size of an array in true basic?

! variable to declase the size of an array in True Basic ! set up a dummy value for array - any initial value > 0 is fine. DIM array$(999) ! ask the user for the length of the array INPUT PROMPT "Enter array size " :size ! resize the array with user defined length MAT REDIM array$(size) ! program end END


Which condition is not necessary in dynamic stack?

in dynamic stack we don't have to initialize the size of array while in static stack we have 2 initialize it ......


What is a implementation on n numbers of term in bubble sorting?

void bubblesort (int* array, int size) { if (!array size<2) return; int last_swap = size; while (last_swap>0) { int n=last_swap; for (int i=1; i<last_swap; ++i) { if (array[i]<array[i-1]) { array[i]^=array[i-1]^=array[i]^=array[i-1]; n=i; } last_swap = n; } }


What is meant by irregular dimensional array?

An irregular dimensional array is a special type of multi-dimensional array.First we must understand that a multi-dimensional array is just an array of arrays. Each element in the array is, itself, an array of elements.A regular multi-dimensional array will be an array of size n, with each element containing a separate array of size m. That is, each sub-array has the same size.An irregular multi-dimensional array will be a multi-dimensional array in which each sub-array does not contain the same number of elements.Regular array:array[0] = new array{0, 1, 2}array[1] = new array{3, 4, 5}array[2] = new array{6, 7, 8}array[3] = new array{9, 10, 11}This regular array is an array of size 4 in which each sub-array is of size 3.Irregular array:array[0] = new array{0, 1, 2}array[1] = new array{3, 4}array[2] = new array{5, 6, 7}array[3] = new array{8, 9, 10, 11}This irregular array is an array of size 4 in which the size of each sub-array is not the same.


What is sparce array?

sparse array is one which has contents lower than its maximum size, that is the array has free or empty locations....


Why fixed size array is not efficient?

It's not exactly true. Array with fixes size are efficient, but do not work well when you have to resize your array. This actually is the answer for your question. Fixed size arrays are not efficient if you have to change the size. Also you cannot destroy them and release memory used to save the array (for that you have to use operator new).


Is there any overhead issues if you make a 2D array arr28 rather than making a 1D array arr16 of size 16 Any memory issues or execution differences between the two?

2D array of size 2x8 and 1D array of size 16


What is the difference between a fixed size array and a variable size array?

The obvious answer is that one has a constant size while the other does not. More specifically, a fixed-size array is one where the size is known at compile time and does not change at runtime. By contrast, the size of a variable-sized array may or may not be known at compile time but may change at runtime. We often refer to a variable-size array as being a dynamic array, however some people (myself included) incorrectly refer to a fixed-size array as being a static array. The misunderstanding largely comes from the fact that we often refer to the heap (or free store) as being dynamic memory because all dynamic variables are allocated there (including variable-size arrays). But the term dynamic array does not refer to the memory, it refers to the dynamic -- as in changeable -- nature of the array itself. By contrast, a fixed-size array is only deemed static if it is statically allocated, in which case it will be allocated in the program's data segment along with all other static variables, global variables and constants. But a local fixed-size array is allocated on the program's stack and is therefore, by definition, non-static. Moreover, you can allocate a fixed-size array on the heap!


What is the sie of an array whos upper bound is 100?

To calculate the size of array the type of array should be given. Ex: if it is of integer type that means int arr[100] and integer is of 4 bytes, then the size of array will be 400 bytes.


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 initialize an array variable in java program?

An array in java is a collection of items stored into a single unit. The array has some number of slots (elements), each slot in the array can hold an object or a primitive value. Arrays in java are objects that can be treated just like other objects in the languageArrays can contain any type of element value , but we can't store different types in a single array. We can have an array of integers or an array of strings or an array of arrays.To create an array in java ,use three steps1. Declare a variable to hold the array2. Create a new array object and assign it to the array variable3. Store things in that array