100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Pascal Data Types and Variables

An overview of Pascal's built-in data types, variable declarations, and how the language's strict typing shapes everyday code.

FoundationsBeginner10 min readJul 10, 2026
Analogies

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.

pascal
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

Was this page helpful?

Topics covered

#Programming#PascalStudyNotes#PascalDataTypesAndVariables#Pascal#Data#Types#Variables#StudyNotes#SkillVeris#ExamPrep