someFunction
does not read or write to the num1
parameter. Thus, someFunction
by definition can't impact the num1
array passed in to it from main
.
This would be the case, regardless of whether array parameters in your language of choice were passed by reference or by value.
As I trace through the algorithm, on the second call, num1[0] is 999
and continues to be until I return back to main.
I suspect you are getting confused by the fact that your variable name in main
and your parameter name in someFunction
are the same. You are seeing num1
as set to a particular value - but that isn't main
's num1
- that is someFunction
's num1
. To make that clearer when debugging, change the name of one of them (either the variable name in main
or the parameter name in someFunction
) to bob
instead.
In terms of the outcome you are trying to achieve I suspect, that perhaps instead of:
public static void someFunction(int[] num1, int count){
if (count!= 0){
int[] temp = {999};
someFunction(temp, count-1);
}
}
you may have meant to write:
public static void someFunction(int[] num1, int count){
if (count!= 0){
num1[0] = 999;
someFunction(num1, count-1);
}
}
Note in particular that (with my suggested change) someFunction
will be writing to the num1
parameter (the parameter passed in, not a new temp
array) - so the array in main
will reflect that change.