HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to PascalVariablesData Types & ConversionOperatorsStringsConditions (if)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
✍️ String
🔁 Condition & Loop
🧩 Function & Procedure
Pascal›Data Types & Conversion

Data Types & Conversion

Basic types and conversion with StrToInt / IntToStr (SysUtils).

Simple enough for a 5-year-old to understand

StrToInt / IntToStr

Example code
1
program H;
2
uses SysUtils;
For conversion functions.
ImportFor conversion functions.
3
begin
4
writeln(StrToInt('40') + 2);
Text to number: 42
Output / InputText to number: 42
5
writeln('Age: ' + IntToStr(36));
Number to text: Age: 36
Output / InputNumber to text: Age: 36
6
end.
ImportOutput / Input
💡 Hint: Don't forget to add uses SysUtils; for conversion/text functions.

About this topic

Pascal's basic types are integer, real number, character, string, and boolean. Each type has defined limits, and the compiler checks these limits.

Integer types come in different widths. If you choose a small type and exceed its limit, you will experience an overflow; some compilers catch this at runtime, while others pass silently. You need to consider the value range from the start.

Pascal does not perform implicit conversions between types. Moving from an integer to a real number is allowed because it is safe; the reverse direction implies data loss, so you must request an explicit conversion function.

What you will learn

  • Basic types and their limits
  • The difference between division operators
  • Type conversion functions
  • The boolean type
  • Subrange and enumerable types

Who is this for?

  • Beginners working with the type system for the first time
  • Those surprised by the division result
  • Those getting overflow errors

When to use?

Choosing the correct value range in algorithm studies prevents incorrect results caused by overflow.

Enumerable types are the cleanest way to express in code that a variable can only take specific values, and they prevent missing conditions.

Common mistakes

Wrong

program Test;
var
  sonuc: Real;
begin
  sonuc := 7 div 2;
  writeln(sonuc:0:2);
end.

The integer division operator discards the fractional part; the result becomes 3, and even if assigned to a real variable, it prints 3.00 instead of 3.50. If you want a decimal result, you need to use the normal division operator.

Correct

program Test;
var
  sonuc: Real;
begin
  sonuc := 7 / 2;
  writeln(sonuc:0:2);
end.

Wrong

program Test;
var
  sonuc: Integer;
begin
  sonuc := 7 / 2;
  writeln(sonuc);
end.

The normal division operator always produces a real number; assigning this value to an integer variable results in a type mismatch error. If you want an integer result, you must use the integer division operator.

Correct

program Test;
var
  sonuc: Integer;
begin
  sonuc := 7 div 2;
  writeln(sonuc);
end.

Wrong

program Test;
var
  deger: Byte;
begin
  deger := 300;
  writeln(deger);
end.

This type can only hold values between zero and two hundred fifty-five; when an out-of-range constant is assigned, the compiler gives an error or warning. If a value calculated at runtime exceeds the limit, it silently wraps around and the result turns out wrong.

Correct

program Test;
var
  deger: Integer;
begin
  deger := 300;
  writeln(deger);
end.

Frequently asked questions

What is the difference between the two division operators?

The slash always produces a real number; the operator written with letters only works with integers and discards the fractional part. There is also a separate operator for the remainder. You have to explicitly choose which one you want.

How do I print a real number?

In the print call, field width and decimal places are specified using colons. If you do not specify them, scientific notation is used, and the output will look very different from what you expect.

What is the purpose of an enumerable type?

It defines the values a variable can take with a limited list: such as days, colors, states. It increases the meaning of the code, and the compiler can warn about missing cases in branches.

Summary

The slash produces a real number.

There is a separate operator for integer division.

Automatic conversion between types is limited.

Overflow occurs if type limits are exceeded.

Real numbers are printed by specifying a format.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code