Pascal Variables and Data Types

Definitions:

Overview of Pascal Data Types:

NameType of DataExamples
StringHolds Text'New York', 'Evan'
IntegerHolds whole numbers3, 6, 1024
RealHolds Decimal Numbers3.14, 503.2
BooleanHolds True or FalseTRUE, FALSE
CharacterHolds a single character'A', 'E'

Strings: When declaring a string variable, you usually indicate its maximum length (1- 255). For example, to create a variable called City that can hold up to 25 characters, you would type: city: String[25]; If you do not include a maximum size, the string is given a default maximum size = 255.

Variable Ranges

Data TypeMinimum ValueMaximum Value
Integer-32,76832,767
LongInt-2,147,483,6482,147,487,647
ShortInt-128128
Real2.9 x 10 E-391.7 x 10 E+38

Rules for Identifier Names

All identifier names, including program names and variable names must follow the following rules:

Examples of Illegal Identifiers: 2Length, AB*3, Len gth.

Operator Precedence

The following precedence table applies to Real and Integer operators. Parentheses always have the highest priority, and operators of equal priority are always performed left to right.

PriorityOperation
First* / DIV MOD
Second+ -

For example: To evaluate 4.0 + 6.0 * 3.0, you must follow the precedence table and perform the multiplication first, and the addition second. Hence, evaluating this expression will always give an answer of 22.0. If you want to perform the addition first, you must include the 4.0 + 6.0 within parentheses: (4.0 + 6.0) * 3.0.

Integer Division

7 / 3 = 2.3333, but 2.3333 is not an Integer. Hence, we need a method of doing division that only results in Integer values. For this we use MOD and DIV:

				

			2	<----  Use DIV to get this result:  7 DIV 3 = 2.
		  _________
		3 |	7
			6
		       ____
			1	Remainder 1	<---   	Use MOD to get this result:
							7 MOD 3 = 1 

Mixed Mode

If you use integers and reals together, integers are automatically converted to reals. For example, if you have the following expression:

Profit := (3.0 * 4.0)/2

the 2 is automatically converted to 2.0 and the result is equal to 6.0.