I have a question regarding the address of arrays. Lets says we have this piece of code:
main(){
int[] numbers = {1, 2, 3};
method(numbers);
}
method(int[] methodNumbers){
methodNumbers= new int[methodNumbers.length];
return methodNumbers;
}
Here's what I think I know. Please correct me if I'm wrong.
So I know there is the main stack frame, method stack frame, and the heap. In our main, the int[] numbers is stored. It is pointing to an address in the heap which is where the indexes are stored. We pass the int[] numbers into the methodNumbers parameter so now they are pointing to the same location in the heap. Inside our method, we declare a new int for our methodNumbers so now the int[] methodNumbers array is pointing to a new location in heap. But in the end we return the methodNumber.
My question is where is the int[] numbersArray pointing to at the end. Is it pointing to the same place or is it pointing to the same location as methodNumbers?
numberspoints to the same object as before the call of the method.