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

{ The purpose of this program is to:

  1.  Demonstrate the use of an array of character variables,
      the Standard Pascal data structure for "strings."
}

program Demonstrate_Strings_with_Standard_Pascal_2;

var A : array [1..10] of char;
    B : char;
    C : array [1..15] of char;
    D : array [1..20] of char;

begin  (* main program *)
   A := 'ABCDEFGHIJ';
   B := 'K';
   C := 'LMNOPQRSTUVWXYZ';
   writeln(A,B,C);
   writeln('**************************');
   writeln('12345678901234567890123456');
   writeln('0        1         2      ');
   writeln('**************************');
   D := A + B + C;  {Can D accommodate an array of 26 elements?}
   writeln(D);
end.  {advanced_pencil-16.p}
%  pc PASCAL/advanced_pencil-16.p
%  a.out
ABCDEFGHIJKLMNOPQRSTUVWXYZ
**************************
12345678901234567890123456
0        1         2      
**************************
ABCDEFGHIJKLMNOPQRST

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

There have been visitors to this page since February 1, 1999.