I'm strugling to understand what is the output of following code (STATIC SCOPE):
program Test:
var a: integer;
procedure Add(a:integer);
begin a:= a+1; end;
procedure Print;
begin a:= a+2; write(a); end;
procedure First;
var a: integer;
begin a:=3; Add(3); Print; end;
procedure Second;
var a: integer;
begin a:=4; Add(4); Print; end;
begin a:=1; Add(5); Second; Print; First; Print; end;
I know when the program starts on stack there is a = 1; So, when i call function Add(5) will it do:
- a = 5+1; or
- a = 1+1; ?
Thank you!
1st iteration: a:=1; //on stack Add(5) results in a:=5+1; (a:=6; // on stack)
or
1st iteration: a:=1; //on stack Add(5) results in a:=1+1; (a:=2; //on stack)