value of callee and caller when using call by references

84 views Asked by At

I encountered a confusion , when i pass a variable x to variable y by reference then both x and y should now point to same location, but the output that i am getting is not same.

Full detail discussion is here: http://gateoverflow.in/94182/programming-output I have tried my best to explain the stuff to user but i am still unable to convience him fully, maybe i am lacking some concept.

rough code sample:

var b : int;
procedure M (var a, int)
begin
a= a*a;
print(a);
end;
procedure N
begin
b= b+1;
M(b);
end;
begin
b=12;
N;
print(b);
end;

enter image description here

I assume that as in question it is given that variables are static , so the value of a b should not change from 13 , but the value of a should be 13*13=169 , but my reasoning is counter to what call by reference is about.

pascal code from unauthorized book, please throw some insights.

1

There are 1 answers

0
Code-Apprentice On BEST ANSWER

I had to review scoping terminology. I had myself confused between static and dynamic scoping. Static scoping is used in all modern programming languages. I conclude that both a and b should have a value of 169 at the respective print statements.