Identifiers and Basic Types - Right (2024)

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.

The declaration of a variable is done in the variable part of the program.The format to be used is:
var
identifier1 : type; {like a:integer;}
identifier2 : type;
.
.
.
identifierN : type;
begin {not in variable declaration part anymore}

The Formatof variables:

The format of a variable, or in general identifier, in Standard Pascalis as follows:

Identifiers and Basic Types - Right (1)

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.

Positive examples for identifiers are:
first, count, name, give, henry18, henry6s.
Negative examples for identifiers are:
18henry, first.name, first-name, *jklpp etc.
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:
integer1:= integer2 + integer3;
integer1:= integer2 - integer3;
integer1:= integer2 * integer3; {'*' stands for multiplication, don'tforget the limits -maxint and maxint}
integer1:= integer2 div integer3; {div takes the integer part of thedivision and assigns it to integer1}
integer1:= integer2 mod integer3; {this is the standard modula operator}

The Real Datatype

The real datatype is to represent real values, but not all real values.It's upper limit is 1.7E-38, where E-38 means a multiplicant of 10 to thepower -38, eg. 15.0E-4 = 0.0015.
It's operators: +', '-', '*', '/'.
real1:= real2 + real3;
real1:= real2 - real3;
real1:= real2 * real3; {'*' stands for multiplication, don't forgetthe limits}
real1:= real2 / real3; {this is the standard division we use everytimein life}

The Char Datatype

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.
The Boolean Datatype
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.
Examples:The first example is an illustrative example showing how the memorycell content holding the variable changes during an assignment.

IllustrativeExample

As you see, contrary to the thoughts of most new pascal students, thecontent of B does not change when A changes.Operator Precedence:
Identifiers and Basic Types - Right (2024)
Top Articles
Latest Posts
Article information

Author: Edwin Metz

Last Updated:

Views: 6394

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Edwin Metz

Birthday: 1997-04-16

Address: 51593 Leanne Light, Kuphalmouth, DE 50012-5183

Phone: +639107620957

Job: Corporate Banking Technician

Hobby: Reading, scrapbook, role-playing games, Fishing, Fishing, Scuba diving, Beekeeping

Introduction: My name is Edwin Metz, I am a fair, energetic, helpful, brave, outstanding, nice, helpful person who loves writing and wants to share my knowledge and understanding with you.