Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

pascal

What are constants in Pascal?

Sheza Naveed

Constants are entities that remain unchanged throughout the program once they have been declared. Pascal allows the declaration of the following types of constants:

Declaring constants

Constants are declared as shown below:

const
constant_name = constant_value;

The following table further illustrates constant declaration:

Constant Type Example
Ordinal (Integer) no_of_employes = 250;
Character Operator = ‘&’ ;
String country = ‘Pakistan’;
Set provinces = ( Punjab, Sindh, Baluchistan, KPK, Gilgit);
Pointer thisPointer = NIL;

Example

The following example shows the use of constants:

program pay_calculation (input,output);
const
tax_deduction = 10000;
bonus = 50000;
basic_pay = 40000;

var
total_pay, final_pay : real;   

begin
   
   total_pay := basic_pay + bonus;
   final_pay := total_pay - tax_deduction;
   
   writeln('The final pay is ',final_pay);
end.

RELATED TAGS

pascal

CONTRIBUTOR

Sheza Naveed
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring