2. Consider the following program: 1). program test(input, output) 2). var a:int
ID: 649678 • Letter: 2
Question
2. Consider the following program:
1). program test(input, output)
2). var a:integer;
3). procedure first;
4). begin write(a); a:=6; write(a); end;
5). procedure second;
6). var a:integer;
7). begin write (a); first; write(a); end;
// The starting point for executing test.
8). begin
9). a:=3; second; write(a);
10). end
The scope of test encloses first and second and has a as an integer variable. first and second do not
enclose each other. In second, a is an integer variable.
Execute this program when this program follows static binding, and execute it when it follows
dynamic binding. Show the contents of the stack and value of the variable a in two places while the
program is in execution. Also show what values will be written out. Whenever an a is written out
show where this a is declared. (25 pts)
Explanation / Answer
The content of stack are as follows
3
3
6
6
6
last 6 is at top
variable a is declared in memory
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.