Question: Title: Array reference and memory allocation Problem description: Given the following code snippet: java int [ ] arr = new int [ 4 ] ;

Title: Array reference and memory allocation
Problem description: Given the following code snippet:
java
int[] arr = new int[4];
arr[0]=200;
arr[1]=868;
\operatorname { a r r [2] ~ = ~ 55 ; }
arr[3]=333;
int[] arr2= arr;
arr2[1]=999;
arr2= new int[3];
arr2[e]=123;
arr2[1]=456;
arr2[2]=789;
Questions:
Please draw the memory structure diagram after arr2= arr; and explain the relationship
between arr2 and arr.
After executing arr2[1]=999, what changes will occur to the contents of the arr array?
Why?
When executing arr2= new int [3], explain the changes in arr2 and arr in memory and
draw the new memory structure diagram.
After the code is executed, what are the contents of the arrays pointed to by arr and
arr2.respectively?
Title: Array reference and memory allocation

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!