36
Question Question 30
Write a note on how single-dimension arrays are represented in memory.
Single-dimensional arrays are lists of information of the same type and their elements are stored in contiguous memory locations in their index order.
Internally, arrays are stored as a special object containing :
- A group of contiguous memory locations that all have the same name and same datatype.
- A reference that stores the beginning address of the array elements.
- A separate instance variable containing the number of elements in the array.
For example, an array grade of type char with 8 elements declared as
char grade[ ] = new char[8];
will have the element grade[0] at the first allocated memory location, grade[1] at the next contiguous memory location, grade[2] at the next, and so forth. Since grade is a char type array, each element size is 2 bytes and it will be represented in memory as shown in the figure given below:
