The Format of a Variable |
The integer Datatype |
The real Datatype |
The char Datatype |
The boolean Datatype |
Examples with assignment |
Operator precedence |
Each variable, the concept of a variable is explained before, has acertain type, that is the type of the value which it is to store. Thereare 4 standard types in Pascal, which are integer, real, char and boolean.
var | |||||
identifier1 : type; {like a:integer;} | |||||
| |||||
| |||||
The format of a variable, or in general identifier, in Standard Pascalis as follows: What you should not use as an identifier is a reserved word. Reservedwords are words which have a special meaning in Pascal, such as "begin","end", "and", "or", "not" etc. Remember, that Pascal is not case sensitive, that is Name and name arerecognized as the same identifier. Moreover, Pascals identifiers are limitedto 8 characters, that is you can write more than 8 characters as a literalname, but Pascal will cut off the longer variables to 8 characters. Forexample "firsteight" and "firsteig" are recognized as the same identifierd.
|
The integer datatype is used to represent integer numbers, that isnumbers which do not have fractions (eg. 13, -5). It has a range between-maxint and maxint-1, where maxint is 32768. If you assign a larger numberthan maxint to a number, maxint is subtracted from the number as many timesas needed to fit this number into the range and you can't detect the error.So beware of this. | |||||
Operators: '+' '-' '*' 'div' 'mod'. | |||||
The syntax is:
| |||||
| |||||||
The char datatype is used to store any single character value, like'c', '8'. It can hold any of the letters, characters, punctuation marksor digit characters that appear on the keyboard. Note that the character'8' and the integer 8 are different. With the integer 8 you can performarithmetic operations whereas with the character '8' you can not. The character,if it is written in the program, is enclosed in single quotes, where asingle quote is a '. However, if the input is a character from theterminal, keyboard, then it is just written without quotes. |
A boolean datatype can only have to values, either true or false. Itis used in conditional statements, (covered later) like if..then, whileetc. The assignment can be as follows: b:=true; or b:=(8<9); which isalso true. You should note that you should not check for equality of realvalues, since even if they are theoretically equal, there can be an errorof Epsilon, the smallest number possible in Pascal, and then your equalityis false. |