Advanced Pascal Programming Language Problems
© 1998 by Dr. Thomas W. MacFarland -- All Rights Reserved
Instructions: Review the following program and see if you can predict the outcome by completing a "pencil trace" of the code. Program output is provided at the end of this page. Compiler: The program was prepared using Standard Pascal on a UNIX-based host computer.
% cat PASCAL/advanced_pencil-12.p
{ Advanced Pascal Programming Language Exercises
Dr. Thomas W. MacFarland
advanced_pencil-12.p
}
{ The purpose of this program is to:
1. Demonstrate an array of integer variables.
2. Demonstrate an array of character variables.
3. Demonstrate an array of real variables.
4. Demonstrate an array of boolean variables.
}
program Demonstrate_Arrays_3;
type A = array[10..20] of integer;
B = array[2..10] of char;
C = array[-10..30] of real;
D = array[2..4] of boolean;
E = array[1..12] of D;
F = array[1..12,1..6] of boolean;
var G,H : integer;
I : A;
J : A;
K : E;
L : F;
begin (* main program *)
for G := 1 to 12 do
for H := 1 to 6 do begin
K[G,H] := true;
L[G,H] := K[G,H];
end;
writeln(G:7);
writeln(H:7);
writeln(I[13]:7);
writeln(J[14]:7);
writeln(K[2,3]:7,L[12,5]:7);
writeln(L[3,2]:7);
end. {advanced_pencil-12.p}
% pc PASCAL/advanced_pencil-12.p
% a.out
12
6
0
0
true true
true