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-11.p
{ Advanced Pascal Programming Language Exercises
  Dr. Thomas W. MacFarland
  advanced_pencil-11.p
}

{ The purpose of this program is to:

  1.  Demonstrate the use of an array of integers.

  2.  Demonstrate the printing of individual elements of
      an array.

  3.  Demonstrate the difference between a variable value 
      and the value of an array element.
}

program Demonstrate_Arrays_2;

var A : array[1..20] of integer;
    B : integer;

begin
   B    := 100;
   A[B] := B + 3; 
   writeln('B = ',B:10);
   writeln('**************');
   for B := 1 to 21 do
     writeln('B = ', B:10);
end.  {advanced_pencil-11.p}
%  pc PASCAL/advanced_pencil-11.p
%  a.out
B =        100
**************
B =          1
B =          2
B =          3
B =          4
B =          5
B =          6
B =          7
B =          8
B =          9
B =         10
B =         11
B =         12
B =         13
B =         14
B =         15
B =         16
B =         17
B =         18
B =         19
B =         20
B =         21

Please send comments or suggestions to Dr. Thomas W. MacFarland

There have been [an error occurred while processing this directive] visitors to this page since February 1, 1999.