Docsity

Programming Languages and Scope - Quiz | CSC 4101, Quizzes of Programming Languages

Toggle sidebar
bg1
Quiz โ€“ 1
February 14, 2006
program scopes (input, output );
var a : integer;
procedure first;
begin
a := 2;
end;
procedure second;
var a : integer;
begin
a:=5;
first;
write(a);
end;
procedure third;
var a: integer;
begin
a:=4;
second;
end;
begin
a := 3;
third;
write(a);
end.
Question: Consider the Pascal program above. Write the output of the program,
assuming:
a) Static scope rules are in effect:
Aswer: 5 2
b) Dynamic scope rules are in effect:
Aswer: 2 3

Partial preview of the text

Download Programming Languages and Scope - Quiz | CSC 4101 and more Quizzes Programming Languages in PDF only on Docsity!

Quiz โ€“ 1

February 14, 2006

program scopes (input, output ); var a : integer;

procedure first; begin a := 2; end;

procedure second; var a : integer; begin a:=5; first; write(a); end;

procedure third; var a: integer; begin a:=4; second; end;

begin a := 3; third; write(a); end.

Question: Consider the Pascal program above. Write the output of the program, assuming:

a) Static scope rules are in effect:

Aswer: 5 2

b) Dynamic scope rules are in effect:

Aswer: 2 3