In: Computer Science
In Java:
int[] A = new int[2];
A[0] = 0; A[1] = 2;
f(A[0],A[A[0]]);
void f(int x, int y) {
x = 1; y = 3;
}
For each of the following parameter-passing methods, saw what the final values in the array A would be, after the call to f. (There may be more than one correct answer.)
a. By value. b. By reference. c. By value-result.
a)With pass by value, none of the actual arguments are changed, so the variables retain the values they were initialized with.
So,. A[0] =0;
A[A[0]] = 0;
b) With pass by reference, the arguments are changed.
After the call to the f the value changed
A[0] = 1;
A[A[0]] = 2; as because we pass an full array and array behaves as a object in java
c) by value result it is same as pass by reference
So, A[0] = 1;
A[A[0]] = 2;