Suppose I have an integer array a
a[0] = 1
a[1] = 2
a[2] = 3
and a function in no particular language
func swap(int l, int r){
int temp = l;
l = r;
r = temp;
}
What is my final value of array a if I execute
int i = 1;
swap(i,a[i]);
in call by value, call by reference and call by name?
I think that call by value would give me the same integer array a = [1,2,3] as changes within the function has no effect to the arguments passed in.
and call by reference would give me the result a = [1,1,3], so what about call by name? Can you show me the steps of the evaluation, I only know that it will pass in the i and a[i] directly into the function call so far but have no ideas what would be affected.
Edit: I have misread the question and array a is supposed to be a = [1,2,3]
initially rather than a= [10,20,30]