pjhayward's Pascal Tutorial


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 TypeBytesNumber typeRange
byte1integer0..255
shortint1integer-127..128
word2integer0..65535
smallint2integer-32767..32768
longword4integer0..4294967295
longint4integer-2147483648 .. 2147483647
qword8integer0 .. 18446744073709551615
int648integer-9223372036854775808 .. 9223372036854775807
integer2, 4 or 8integersame as smallint, longint or int64
cardinal2, 4 or 8integersame as word, longword or qword
real4 or 8floating pointsystem dependent
single4floating point1.5E-45 .. 3.4E38, 7-8 significant digits
double8floating point 5.0E-324 .. 1.7E308, 15-16 significant digits
extended10floating point1.9E-4951 .. 1.1E4932, 19-20 significant digits
comp8floating point -2E64+1 .. 2E63-1, 19-20 significant digits
currency8fixed 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 TypeSize in bytesDescription
char1Stores a single ASCII character. i.e. 'a'
string[size]sizeAlso 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].
stringvariableThe 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.
widestringvariableSame as string, but in Unicode format - that means that each character now takes twice as much space. It also allows you to create multi-lingual applications, since Unicode is required for many international characters.
pchar4+size of stringpchar is a pointer to a null terminated string. This is useful when working with routines written in other languages, such as C.

Next