Pascal Data Types

Introduction
A data type is the nature of a value to be taken or stored in the specified memory location. It defines or tells the program the amount of computer memory to be set aside for that value.

Data type categories:
 * 1) Simple / standard data type.
 * 2) Structured data type.
 * 3) User defined data type.
 * 4) Pointer type data

Standard datatypes
Integer:

It is a whole number, or a number without a fractional part. It can either be negative or a positive number i.e the number must be preceded by a sign (+, -) and in the absence of a sign, then the number is assumed to be positive. The range of integers is between -32768 and +32767 and it occupies two bytes in memory. Example: Var x,j,n: integer; Real:

It is a number with fractional part (a floating point number). Real numbers occupy six bytes in memory with 11 digits of accuracy.

Example: var x, j, n: real; Char:

It is a single character enclosed within single quotes(opening and closing single quotes). Example: var stdInitial, stream: char Boolean:

In cases where you would like to have a logical value instead of a an arithmetic value, you can use the boolean type to store either true or false values in it. It occupies one byte of memory.

Example: var p, r, s: boolean;

Other pascal simple data types
These are modifiers / modified versions in later versions of pascal for integer and real data types, and are provided to facilitate the programming. They depend on the compiler (math co-processor).

Longint: It is integer type which can store larger values than the normal integer. Its range is from -2147483648 to +2147483647. It occupies four (4) bytes of memory. Shortint: It is an integer type which stores smaller values than the normal integer. The range is between -128 to +127. It occupies one byte of memory. Byte: The range is from 0 to 255 (unsigned shortint). It occupies one byte of memory. Word: The range is from 0 to 65535 (unsigned integer). It occupies two bytes of memory (same as integer). Single: This is a real number whose range is from 1.5 * 10-45 to 3.4 * 10 38. It occupies four bytes of memory with 7 to 8 digits of accuracy. Double: The range is from 5.0 * 10324 to 1.7 * 10308. It occupies eight bytes of memory and provides 15 or 16 digits of accuracy. Extended: It is a real number whose range is 1.9 * 10-4951 to 11.1 * 104932. It occupies ten bytes of memory and provides 19 to 20 digits of accuracy. Comp: This real number has the range (can store numbers) from -263 + 1 to 263 + 1. It occupies eight bytes of memory with accuracy equal to the norml real type.

User defined data types
Enumerated: Is a user defined type where the user specifies the items whose value starts from zero(0) to n-1 where n is the total number of items in the list.

Example: Type beverages = (Tea, Coffee, cocoa); Var tea_break: beverages; Subrange: Allows the programmer to limit / validate or determine the range of numbers to be accepted or entered in a variable. Example: Type mark = 1..100; var score1, score2, score3: mark;

Structured data types
Arrays: A goup of variables referenced to by a single name see Pascal Arrays Example: var marks = array[1..10] of integer; Records: It is a group of fields with related data about a single entity. Example: type studDetails = record studNo: char; stdName = array[1 to 15] of char; end; Files: A file is a collection of data/ records in a document saved under a single name. Pascal file organization falls in two categories; Sequential and random, there are basically two types of disk files; Binary and Text files see Pascal Records and Files. Example: type studRec = record studNo: char; stdName = array[1 to 15] of char; end; Var  studDetails: studRec; studFile: file of studRec; Sets: It is a collection of elements e.g of ordinal or subrange data type see Pascal Sets and Pointers. Example: Type No0to20 = set of 1..20;

Pointer data type
A pointer is a variable which stores the address of another variable to declare a pointer in pascal the caret is used see Pascal Sets and Pointers Example: ptrPointer: ^integer;