Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

program main; var a,b,c: integer; procedure P; var c:integer; procedure Q; var a

ID: 667330 • Letter: P

Question

program main;

        var a,b,c: integer;

                procedure P;

                var c:integer;

                     procedure Q;

                     var a,b:integer;

begin (* Q *)

a := 1;

b := a-c;                      

write(' a,b,c from Q',a,b,c)      (*prints a, b and c*)

                         end; (* Q *)

                    procedure R;

                    var c,d:integer;

                        procedure S; (* S *)

                        begin

c := a-b+3;

a := b+d;                     

write(' a,b,c from S',a,b,c)        (*prints a, b and c*)

                        end; (* S *)

                     begin (* R *)

a := a-2;

c := 4; d := 1;              

Q;

S;

                     end; (* R *)

                 begin (* P *)

c := -1;

a := a+1;

b := a-c;                     

R;

Q;

                 end; (* P *)

           begin (* Main *)

    a := 3;

    b := 2;

    c := 4;

    write(' a,b,c from Main',a,b,c)                     (*prints a, b and c*)

    P;

            end. (* Main *)

Print the output of the write statements in the code (i.e. values of a,b and c at each of these three positions) under static scoping rules i.e follow the static link pointer to look for non local reference

Explanation / Answer

output of the program is

1

2

10

42

11