Pascal Data Types and Variables
Every variable in Pascal must be declared with an explicit type in a var section before it can be used, using the syntax 'name: Type;', and that type determines both how much memory the variable occupies and what operations are legal on it. Pascal's built-in simple types include Integer for whole numbers, Real for floating-point numbers, Char for a single character, Boolean for true/false values, and String for text, each with well-defined ranges and behavior specified by the language standard rather than left to the compiler's discretion.
Cricket analogy: Declaring a variable's type before use is like a team submitting its official playing eleven before the match, once submitted, you can't suddenly field a twelfth player, and Pascal won't let you use a variable whose type wasn't declared first.
Ordinal Types: Integer, Char, and Boolean
Integer, Char, and Boolean are all ordinal types in Pascal, meaning every value has a well-defined predecessor and successor, which is why functions like Succ, Pred, and Ord work on all of them. An Integer in Free Pascal typically holds values from -2147483648 to 2147483647 (32-bit signed), a Char holds one byte representing a single character such as 'A' or '7', and a Boolean holds only True or False, taking part directly in conditions used by if and while statements without needing comparison operators.
Cricket analogy: Just as every over in cricket has a well-defined next over, over 24 is always followed by over 25, ordinal types in Pascal have a well-defined successor, so Succ(5) is always 6.
Real Numbers and Strings
The Real type stores floating-point numbers and is not an ordinal type, so Succ and Pred don't apply to it; Free Pascal also offers more precise variants like Double and Extended when you need finer control over precision and range. The String type holds sequences of characters and, unlike C's manually managed character arrays, Pascal strings track their own length automatically, so concatenating with '+' or comparing with '=' just works without manual buffer management, though Free Pascal internally offers both a legacy ShortString (max 255 characters) and a more flexible AnsiString for longer text.
Cricket analogy: A player's batting average, a continuous decimal figure like 52.34, behaves like a Real number, you can't ask for the 'next' batting average the way you can ask for the next over, since there's no fixed step between values.
Type Compatibility and Conversion
Pascal will not silently convert between incompatible types, so assigning a Real value to an Integer variable or vice versa requires an explicit conversion function like Round, Trunc, or Int; only assigning an Integer to a Real is allowed implicitly, since that widening never loses information. This strictness catches a whole category of bugs at compile time, like accidentally comparing a Char to an Integer, that would otherwise surface as confusing runtime behavior in more permissive languages.
Cricket analogy: Converting a Real like 45.8 into an Integer requires an explicit Round or Trunc call, just as converting a player's raw strike rate into a rounded, reportable statistic requires an explicit, deliberate rounding decision by the scorer.
program DataTypesDemo;
var
score: Integer;
average: Real;
grade: Char;
passed: Boolean;
studentName: String;
begin
score := 87;
average := 3.0 * score / 4; { Integer promotes to Real automatically }
grade := 'B';
passed := score >= 60;
studentName := 'Priya';
WriteLn(studentName, ' scored ', score, ' (', average:0:2, ' avg), grade ', grade);
WriteLn('Passed: ', passed);
WriteLn('Rounded average: ', Round(average));
end.Ordinal functions Ord, Succ, and Pred work on any ordinal type, not just Integer. For example, Ord('A') returns 65 (its ASCII code), and Succ('A') returns 'B', which is genuinely useful for looping through characters or enumerated types.
Do not assume Pascal's default Integer is always 64-bit. In Free Pascal, the plain Integer type is commonly 32-bit signed by default depending on target platform and mode settings; if you need a guaranteed 64-bit whole number, declare the variable explicitly as Int64.
- Every Pascal variable must be declared with an explicit type before use, using 'name: Type;'.
- Integer, Char, and Boolean are ordinal types with well-defined successors and predecessors via Succ/Pred/Ord.
- Real (and Double/Extended) store floating-point numbers and are not ordinal types.
- Pascal's String type manages its own length automatically, unlike C-style character arrays.
- Implicit conversion only goes from Integer to Real, never the reverse, without an explicit function.
- Round, Trunc, and Int are the standard functions for converting Real values to Integer.
- Strict typing catches many category-of-bug errors, like comparing a Char to an Integer, at compile time.
Practice what you learned
1. Which of these is NOT an ordinal type in Pascal?
2. What function converts a Real value to the nearest Integer in Pascal?
3. Which conversion happens implicitly in Pascal without an explicit function call?
4. What does Ord('A') return in Pascal?
5. How does Pascal's String type differ from a C-style character array?
Was this page helpful?
You May Also Like
Pascal Program Structure
How every Pascal program is organized into a program heading, declaration sections, and a main statement block.
What Is Pascal?
An introduction to the Pascal programming language, its origins, design philosophy, and where it is still used today.
Your First Pascal Program
Write, compile, and run a simple Pascal program that reads user input and prints output, tying together everything from earlier topics.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics