ana sav wrote:thanks ruben,
but what i am thinking is when we pass array referece as a argument to function,
whatever changes we made to that ref. get reflected in main.isn't it ?
Hi Ana,
No, actually that's not the way it works. When you have a method that takes an array reference as an argument, for example:
And you call that method this way:
What happens is that you copy the value of i (which, like any reference variable is just a bit
pattern which denotes the location of the array object itself) to the a parameter in the method. That means that both i and a will point to the same array object (and you can even modify the array elements through the reference a.) But if you reassign a itself, it won't affect the array object that reference i points to. It will just make a point to a different array (or possibly set it to null) without affecting i.
Does that make things more clear?