CONSTANTS
When writing programs, it is desirable to use values which do not change during the programs execution. An example would be the value of PI, 3.141592654

In a program required to calculate the circumference of several circles, it would be simpler to write the words PI, instead of its value 3.14. Pascal provides CONSTANTS to implement this.

To declare a constant, the keyword const is used, followed by the name of the constant, an equals sign, the constants value, and then a semi-colon, eg,


	const PI = 3.141592654;

From now on, in the Pascal program, you use PI. When the program is compiled, the compiler replaces every occurrence of the word PI with its actual value.

Thus, constants provide a short hand means of writing values, and help to make programs easier to read. The following program demonstrates the use of constants.


	program CIRCUMFERENCE (input,output);
	const   PI = 3.141592654;
	var     Circumfer, Diameter : real;
	begin
	        writeln('Enter the diameter of the circle');
	        readln(Diameter);
	        Circumfer := PI * Diameter;
	        writeln('The circles circumference is ',Circumfer)
	end.


Copyright B Brown/P Henry, 1988-1999. All rights reserved.