7. (10 points; 2 points each part) For each code fragment below, show a memory d
ID: 3727442 • Letter: 7
Question
7. (10 points; 2 points each part) For each code fragment below, show a memory diagram that traces the program's execution and give the value in the array data and the int variable size (part e only) after the method has executed. Also, show the value of the data array under the line that says "show result here." a) /7 calling method int[] data = { 3, 6, 9 }; method(data, 7); / show what is in the array data at this point: public static void method int] source, int value) source[1] value; = Heap Main Stack Frame Identifier Address Contents Identifier |Address Contents 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 101 102 103 Method Stack Franm Identifier Address Contents 200 201 202Explanation / Answer
For part e .
The values in array after calling the method will be {0,0,3.1}
How ?
Before calling we are initializing array using for loop .
by i/2.
As loop will run three time .
iteration 1.
i=0
data[0]=i/2=0
iteration 2
i=1
data[1]=i/2=0
iteration 3
i=2
data[1]=i/2=1
so initially dat araay is {0,0,1}
size=3.
method is called with these values
and value at size-1 is changed means 3.1 is assigned at data[0] because of call by reference.
but size variable is called using call by value hence its value is not changed
so size will remain 3.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.