The following are the various variables available in pascal language.
- Integer
- Character
- Constants
- Real
- Enumerated
- Subrange
Integer is a positive or negative number without decimal value. Integer is of only number, without comma and decimal value. The following is an example.
[c]age: integer = 24;[/c]
A
char
will store a single character. The utilization of byte or char as data type gives documentation with regards to the reason for the utilization of the specific variable. The following is an example.
[c]
var ch: char;
c: byte;
begin
ch := 'A'; c := 65; { are the same action, and are legal }
ch := 65; c := 'A'; { while they are internally the same values,
direct assignment between Chars and Bytes is illegal }
end.[/c]
The constants will make a code more efficient and pascal coding will allow character, string, logical constants. The the constants will be declared with the
const
. The following is the syntax declaration.
[c]const Identifier = contant_value;[/c]
The following is an example.
[c]
PIE = 3.141592;
NAME = 'Welcome To SPlessons';[/c]
The user defined data types are called as enumerated types and in this case the values will be specified in a list format. The following is the syntax for the enumerated data types.
[c]type enum-identifier = (item1, item2, item3 etc )[/c]
The following is an example.
[c]type
Technologies = (Java, sql server, php, c, c++);[/c]
The sun range type data types are used to keep the restrictions on range of the variable and the following is an better example to understand.
[c]var speed: 60 ... 100;[/c]
The real is the another data type to hold the decimal values and it will have a range from 3.4x10-38 to 3.4x1038. The following is an example which describes all the data types.
Test.pas
[c]
PROGRAM Test;
VAR
x : REAL;
i : INTEGER;
j : INTEGER;
BEGIN
x := 12.449;
i := 10;
j := -300;
WRITE('This is some text');
WRITELN('Unformatted integer ',i);
WRITELN('Unformatted integer computation ',i*i);
WRITELN('formatted integer',i:4);
WRITELN('formatted integer',j:4);
WRITELN('Unformatted real ',x);
WRITE('Formatted real');
WRITE(x:8:2);
WRITELN('all in one line');
END.
[/c]
In the above example, x, i, j are the variables with respective data types real, integer, integer. The pascal language is not a case sensitive language. The
writeln
is used to print the data which was given by user.
Output: Now compile the code result will be as follows.
[c]This is some textUnformatted integer 10
Unformatted integer computation 100
formatted integer 10
formatted integer-300
Unformatted real 1.2449000000000000E+001
Formatted real 12.45all in one line[/c]