If f
and g
are defined like this:
void f(int[] x, int[] y, int p, int q) {
for (int i = 0; i < x.length; ++i) {
x[i] = 2 * x[i];
}
x = new int[5];
for (int i = 0; i < 5; ++i) {
x[i] = 0;
}
y[3] = 5;
p = q + 1;
}
void g() {
int[] x = {1, 2, 3, 4};
int[] y = {9, 7, 6, 5};
f(y, x, y[0], x[0]);
for (int p : x) {
System.out.print("" + p + " ");
}
for (int q : y) {
System.out.print("" + q + " ");
}
System.out.println();
}
then if you run g()
, it prints 1 2 3 5 18 14 12 10
, and I don't know why.
How do p
and q
even come into the equation?