Title here
Summary here
Constants are values that cannot be changed during the execution of a program. Below is an example of how to define and use constants in Pascal.
program Constants;
uses
SysUtils, Math;
const
s: string = 'constant';
n: Integer = 500000000;
var
d: Double;
begin
Writeln(s);
d := 3e20 / n;
Writeln(d);
Writeln(Int64(d));
Writeln(Sin(n));
end.
To run this Pascal program, save the code in a file with a .pas
extension (e.g., constants.pas
) and then use a Pascal compiler, such as Free Pascal Compiler (FPC) or Delphi, to compile and run the program.
Here is how you can compile and execute it using Free Pascal Compiler:
$ fpc constants.pas
$ ./constants
Expected output:
constant
6.0E+11
600000000000
-0.284704073237544
Now that we understand how to declare and use constants in Pascal, let’s continue learning more about the language.