- Pascal - Classes
- Pascal - Objects
- Pascal - Date & Time
- Pascal - Units
- Pascal - Memory
- Pascal - File Handling
- Pascal - Sets
- Pascal - Variants
- Pascal - Records
- Pascal - Pointers
- Pascal - Arrays
- Pascal - Booleans
- Pascal - Strings
- Pascal - Variable Scope
- Pascal - Procedures
- Pascal - Functions
- Pascal - Loops
- Pascal - Decision Making
- Pascal - Operators
- Pascal - Constants
- Pascal - Variable Types
- Pascal - Data Types
- Pascal - Basic Syntax
- Pascal - Program Structure
- Pascal - Environment Setup
- Pascal - Overview
- Pascal - Home
Pascal Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Pascal - Constants
A constant is an entity that remains unchanged during program execution. Pascal allows only constants of the following types to be declared −
Ordinal types
Set types
Pointer types (but the only allowed value is Nil).
Real types
Char
String
Declaring Constants
Syntax for declaring constants is as follows −
const identifier = constant_value;
The following table provides examples of some vapd constant declarations −
Sr.No | Constant Type & Examples |
---|---|
1 | Ordinal(Integer)type constant vapd_age = 21; |
2 | Set type constant Vowels = set of (A,E,I,O,U); |
3 |
Pointer type constant P = NIL; |
4 |
e = 2.7182818; velocity_pght = 3.0E+10; |
5 | Character type constant Operator = + ; |
6 | String type constant president = Johnny Depp ; |
The following example illustrates the concept −
program const_circle (input,output); const PI = 3.141592654; var r, d, c : real; {variable declaration: radius, dia, circumference} begin writeln( Enter the radius of the circle ); readln(r); d := 2 * r; c := PI * d; writeln( The circumference of the circle is ,c:7:2); end.
When the above code is compiled and executed, it produces the following result −
Enter the radius of the circle 23 The circumference of the circle is 144.51
Observe the formatting in the output statement of the program. The variable c is to be formatted with total number of digits 7 and 2 digits after the decimal sign. Pascal allows such output formatting with the numerical variables.
Advertisements