Quick Test 15: Scope of variables, passing by value vs. passing by reference

1. What is the scope of each object in the following program

PROGRAM VariableTypes;
Var a: real;

PROCEDURE Proc1(b: real);
Var c: real;
Const d = 10.0;
begin
  c := b+d;
  Writeln(c);
end;
 

Function Proc2(Var e: real): real;
Const f = 20.0;
begin
  Proc2 := e+f;
end;

Var g: real;

begin
  a := 10.0;
  Proc1(a); 
end.
 

 
local
global
parameter
neither
a
b
c
d
e
f
g
2. Consider the program below

PROGRAM QuickTest15
Var x: integer;
PROCEDURE Show(Var a: integer);
begin
  write(a,' ');
  a := a + 1;
end;

begin
  x := 0;
  Write(x,' ');
  Show(x);
  Write(x);
end.

The procedure is called using the technique of
Passing by value
Passing by reference
And, hence the result will be

3. What will be the output of the next program?

PROGRAM DoubleNames;
Var x: integer;

PROCEDURE Show;
Var x: integer;
begin
  x := 1;
  x := x*x;
  Write(x,' ');
end;

begin
  x := 0;
  Show;
  Write(x);
end.

Cannot have two identical names for variables!
0 0
1 0
0 1
1 1