Introduction to the Pascal Programming Language

© 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/intro_pencil-04.p
{ Introduction to the Pascal Programming Language
  Dr. Thomas W. MacFarland
  intro_pencil-04.p       
}

{ The purpose of this program is to:

  1.  Demonstrate the use of integer variables and how these 
      variables can appear when printed using simple format 
      operations.  

  2.  Demonstrate how a variable can easily change value, if 
      appropriately directed in the program. 
}
program Demonstrate_the_use_of_Integers;

var X, Y, Z : integer;

begin

   X := 88;
   Y := 03;
   Z := X + Y;

   write('  X = ', X:4);
   write('  Y = ', Y:4);
   write('  Z = ', Z:4); writeln;

   Z := X - Y;

   write('  X = ', X:4);
   write('  Y = ', Y:4);
   write('  Z = ', Z:4); writeln;

end.  { intro_pencil-04.p      } 
% pc PASCAL/intro_pencil-04.p
% a.out
  X =   88  Y =    3  Z =   91
  X =   88  Y =    3  Z =   85

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

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