I am needing to find the result of the following code when x and y are passed-by-value and also when passed-by-name.
PROGRAM EX1;
int i; //global
int A[3]; //global
PROCEDURE P1(int x, int y)
Begin
y:=2;
PRINT(x);
i:=3;
PRINT(x);
i:=3;
PRINT(x);
PRINT(y);
End;
BEGIN //main
A[1]:=7; A[2]:=13; A[3]:=11;
i:=1;
P1(A[i],i); //first call
P1(i,A[i]); //second call
END.
Here is what I concluded if x and y are pass by value: Outputs: 13, 11, 11, 3 Second Output: 1, 3, 3, 11. If that is wrong please help me understand why.
I am also not sure how pass-by-name would work in this code from the examples I have seen. Please help with that as well.
Assume static scoping.