Constants are entities that remain unchanged throughout the program once they have been declared. Pascal allows the declaration of the following types of 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; |
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
CONTRIBUTOR
View all Courses