pjhayward.net Home
Got a question?
Tutorial Home
Preparation
Lesson One  Sample Program
Lesson Two  Program Structure
Lesson Three  Data Types and Constants
Lesson Four  Variables
Lesson Five  Text I/O
Lesson Six  Subroutines
Lesson Seven  Conditional Statements
Lesson Eight  Arrays
Lesson Nine  Loops
Lesson Ten  Units
  Lesson Three  Data Types and Constants
In pascal, you have a number of different ways to store data. In short, you can store it as a number, as text, as binary data, or any combination of the three. You should become familiar with the basic data types.
Numerical Types
Text/Character Types
Binary Types
Numbers 
Data Type  Bytes  Number type  Range 
byte  1  integer  0..255 
shortint  1  integer  127..128 
word  2  integer  0..65535 
smallint  2  integer  32767..32768 
longword  4  integer  0..4294967295 
longint  4  integer  2147483648 .. 2147483647 
qword  8  integer  0 .. 18446744073709551615 
int64  8  integer  9223372036854775808 .. 9223372036854775807 
integer  2, 4 or 8  integer  same as smallint, longint or int64 
cardinal  2, 4 or 8  integer  same as word, longword or qword 
real  4 or 8  floating point  system dependent 
single  4  floating point  1.5E45 .. 3.4E38, 78 significant digits 
double  8  floating point  5.0E324 .. 1.7E308, 1516 significant digits 
extended  10  floating point  1.9E4951 .. 1.1E4932, 1920 significant digits 
comp  8  floating point  2E64+1 .. 2E631, 1920 significant digits 
currency  8  fixed point  922337203685477.5808..922337203685477.5807 (fixed at 4 digits < 1) 
As you can see, there are a LOT of different ways to describe numbers. In general, if you need an integer, use the integer type. The compiler will automatically decide which size integer to use. If you need a floating point number, you'll need to determine the largest number it should hold, and select your type based off of that. You should become accustomed to this method for selecting your data types.
Text and Characters 
Data Type  Size in bytes  Description 
char  1  Stores a single ASCII character. i.e. 'a' 
string[size]  size  Also known as a shortstring. This is the original Pascal string. It works as an array of characters, with the length of the actual string stored in varname[0]. 
string  variable  The current default string type is a dynamically allocated array of characters. To get or change the length, use the Length and SetLength procedures. See Lesson 8 for more information on dynamic arrays. 
widestring  variable  Same as string, but in Unicode format  that means that each character now takes twice as much space. It also allows you to create multilingual applications, since Unicode is required for many international characters. 
pchar  4+size of string  pchar is a pointer to a null terminated string. This is useful when working with routines written in other languages, such as C. 
Next
