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-06.p
{ Introduction to the Pascal Programming Language
  Dr. Thomas W. MacFarland
  intro_pencil-06.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 the use of a constant value.

  3.  Demonstrate the use of maxint and how the value of 
      maxint is platform specific.

  4.  Bring attention to the need for detail when naming
      variables and possible problems that may develop when
      incorrectly mixing upper case and lower case when
      variables are declared and used (i.e., MaxInt <> maxint).
}
program Demonstrate_More_Work_With_Integer_Types_and_maxint;

const   
    MaxInt    = 32767;

var A, B, C   : integer;

begin

   A := MaxInt;
   B := 1;
   C := A + B;

   writeln('MaxInt = ', MaxInt:15);
   writeln('A      = ', A     :15);
   writeln('B      = ', B     :15);
   writeln('C      = ', C     :15);
   writeln('MaxInt = ', MaxInt:15);  {MaxInt <> maxint}
   writeln('maxint = ', maxint:15);

   C := maxint + 1;                  {What happens when you add 1}
                                     {to Standard Pascal maxint? }

   writeln('C      = ', C     :15);  {to maxint?                 }

end.  { intro_pencil-06.p      } 
% pc PASCAL/intro_pencil-06.p
% a.out
MaxInt =           32767
A      =           32767
B      =               1
C      =           32768
MaxInt =           32767
maxint =      2147483647
C      =     -2147483648

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

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