# Pascal Variables and Data Types

### Definitions:

- Variable: provides temporary storage of data.
- Data Type: defines the type of data that will be stored in a variable.
- VAR Heading: every variable must be assigned a data type and given a unique name.
Declaration of variables must be done in the VAR heading section.

### Overview of Pascal Data Types:

Name | Type of Data | Examples |

String | Holds Text | 'New York', 'Evan' |

Integer | Holds whole numbers | 3, 6, 1024 |

Real | Holds Decimal Numbers | 3.14, 503.2 |

Boolean | Holds True or False | TRUE, FALSE |

Character | Holds 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 Type | Minimum Value | Maximum Value |

Integer | -32,768 | 32,767 |

LongInt | -2,147,483,648 | 2,147,487,647 |

ShortInt | -128 | 128 |

Real | 2.9 x 10 E-39 | 1.7 x 10 E+38 |

### Rules for Identifier Names

All identifier names, including program names and
variable names must follow the following rules:
- Must begin with a letter or underscore (_)
- Can only contain letters, numbers, or underscore (_)
- Cannot contain any blank spaces

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.

Priority | Operation | |

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.