Computer Applications
Answer
An array is a collection of variables of the same type that are referenced by a common name. It is a reference data type which stores data values in contiguous memory locations. An array is declared and initialized as follows:
int arr[] = new int[10];
The significance of arrays are as follows:
- Easy to specify — The declaration, allocation of memory space, initialization can all be done in one line of code.
- Free from run-time overheads — There is no run-time overhead to allocate/free memory, apart from once at the start and end.
- Random access of elements — Arrays facilitate random (direct) access to any element via its index or subscript.
- Fast Sequential Access — It is usually faster to sequentially access elements due to contiguous storage and constant time computation of the address of a component.
- Simple code — As arrays facilitate access of multiple data items of same type through a common name, the code becomes much simpler and easy to understand.
Related Questions
Given an array 12, 3, 8, 5. What will be array like after two passes of bubble sort?
- 12, 3, 8, 5
- 3, 8, 12, 5
- 3, 5, 8, 12
- 12, 3, 5, 8
An array
18, 13, 2, 9, 5
is
13, 2, 9, 18, 5
after three passes. Which sorting technique is applied on it?What is meant by index of an element ? How are indices numbered in JAVA ?
Determine the total bytes required to store B[17], a char array.