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

type String30  = array[1..30] of char;
     String15  = array[1..15] of char;
     String10  = array[1..10] of char;

var  A   : String15;
     B   : char;
     C   : String10;
     D   : String30;
     E   : integer;

begin  (* main program *)
   C := '0123456789'; 
   B := 'A';
   A := 'BCDEFGHIJKLMNOP';
   writeln(C,B,A);
   writeln('**************************');

   for E := 1 to 15 do
      D[E] := C[E];
   D[16] := B;
   for E := 1 to 15 do
      D[E + 11] := A[E];
   for E := 24 to 30 do D[E] := ' ';
   writeln(D);
end.  {advanced_pencil-15.p} 
%  pc PASCAL/advanced_pencil-15.p
%  a.out
0123456789ABCDEFGHIJKLMNOP
**************************
01234567890BCDEFGHIJKLM      

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.