You are on page 1of 3

Elementary Data Types It you think of programming as a special code that you are deciphering or need to encrypt so that

special agent 'PC' can follow the instructions, then you can make programming fun! So what are elementary data types? 'Elementary' suggests basic information, so think of elementary data types as some basic types of code that is necessary to tell 'Secret Agent PC' what data is being sent, received or processed, alright?

The basic data types are: Integers (e.g. 1, 45, 90. That is a whole number with no decimals) Real Numbers (e.g. 45.5, 0.95. That is a number with a decimal) Characters (referred to as Char in Pascal. e.g. 'L', 'E', or 'R'. That is, a letter!) String (e.g. Pamella, 994-2354, Stop!, Enter, USA, ***B12***. That is a combination of characters) In writing a Pascal program, you should state what data types you will be using. This is called declaring your variables. So we indicate that these elementary data types will contain values that will change (vary) during the life of the program as numbers and / or characters are swapped in and out of the data names. How do we do it? Here is the code:

VAR variable_Name : Data_type;

Note the five important pieces in the above statement: VAR indicates that the data will vary during the program Variable_Name indicates the name that you the user will give, just as you, your family, friends and pets have a name for a each person

: separates the name(s) of the variables from the data type. It is similar to english when you have commas and other punctuation. Data_Type will be either Integer, Real, or Char ; represents the end of the program line

So some examples that use variables which can only contain integer data (numbers) are: VAR Mark : Integer; example VAR Age : Integer; VAR Number_of_children : Integer; example E.g. Mark can contain the values 20, 15, 67, for

E.g. Age can contain 34, 16, 18, for example E.g. number_of_children can contain 2, 3, 6, for

Notice that these three variables have been declared for the same data type, which is Integer. These variables can also be declared on one line, as follows: Integer data type VAR Mark, Age, Number_of_children : Integer;

So some examples that use variables which can only contain real data (numbers) are: VAR Average_Mark : Real ; 90.0, for example VAR temperature : Real ; 30.1, or 29.7, for example VAR km_per_hr : Real ; 104.2, for example E.g. Average_Mark can contain the values 55.8, 75.9,

E.g. temperature can contain the values, 98.4, 32,1,

E.g. km_per_hr can contain the values 60.4, 34.9, or

Again, these three variables can be declared on one line as follows:

Real data type VAR Average_Mark, Temperature, km_per_hr : Real; Some examples that use variables which can only contain character data (letters ) are: VAR Grade : char; example VAR Result : char ; VAR Raining : char ; example E.g. Grade can contain the values 'C', 'B', or 'A' for

E.g. Result can contain the values, 'P', or 'F', for example E.g. Raining can contain the values 'Y' or 'N', for

Notice that the values entered in these variables are enclosed in single quotes. Yes indeed, here we go with writing the above three variables on one line: VAR Grade, Result, Raining : Char;

String data type Some examples that use variables which can contain combinations of letters, letters and numbers, combinations of letters with numbers along with special characters are: VAR Name: string; . VAR Address : string ; . VAR Tel_Number : String ;
.

E.g. Name can contain the values 'Carla Sinclair', 'Morris Benjamin', or 'Alrick Taylor' for example E.g. Address can contain the values, 'Pineapple . Avenue', for example
E.g. Tel_Number can contain the values '1-876-342-2569' ,. for example

Notice that the values entered in these variables are enclosed in single quotes. This is how we write the three above variables on one line: VAR Name, Address, Tel_Number : string;

You might also like