Pascal Constants
 


In real world, we meet many constants, such as pi = 3.1415926513...
Pascal has a good facility to use the constants.

How to define our own constant ?
 Just like a variable definition, we just give const above our constants AND start tayloring our needs.


const
:
myconst = 1234;
:
:
(Like variable definition)

We just omit the constant type, Pascal will understand it. We can use it just like a normal variable. Example :




const
myconst = 1234;
var
i : word;
begin
i:=40;
writeln(i*myconst);
end.


Constants is unchangeable. If you try to change it, Pascal will say error.

const
myconst : mytype = thevalue;

example:

const
abc : word = 1234;

You may not declare constants with values exceeding the type, like these :

const
aaa : word = 100000; { Illegal because word is integer ranging 0-65535 }
bbb : byte = 123.44; { Illegal because of the fractional part }
ccc : string = 123; { Illegal because incompatible type }

How can we modify them inside our program ?

const
myconst : word = 1234;
var
i : word;
begin
i:=40; myconst:=1000;
writeln(i*myconst);
end.

(c) Shilpa Sayura Foundation 2006-2017