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›Operators

Operators

Math (+ - * div mod), comparison (= <>) and logic (and or not).

Simple enough for a 5-year-old to understand

div and mod

Example code
1
program H;
2
begin
3
writeln(7 div 2);
Integer division: 3
CodeInteger division: 3
4
writeln(7 mod 2);
Remainder: 1
CodeRemainder: 1
5
end.
Code
💡 Hint: Integer division uses div, remainder uses mod. Equality is =, inequality is <>.

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (1 left)

1.Print the remainder (modulo) of 23 divided by 4.

🎯 Expected output: 3

Loading editor…

About this topic

Pascal's operators are grouped as arithmetic, comparison, and logical. Most are familiar, but there are a few important differences: the not-equal sign is written with angle brackets, and logical operators are expressed as words.

The most critical detail is operator precedence rules. In Pascal, logical operators have higher precedence than comparison operators. This is the opposite of many languages and leads to unexpected compilation errors when parentheses are not used.

This rule is Pascal's most common pitfall. Using parentheses in any condition that combines two comparisons both prevents errors and makes the intention readable.

What you will learn

  • Arithmetic operators
  • Comparison operators
  • Logical operators
  • Operator precedence rules
  • The necessity of using parentheses

Who is this for?

  • Those who encounter errors when writing conditions
  • Developers coming from the C family
  • Those wondering about precedence rules

When to use?

Using parentheses in every expression combining multiple conditions is practically a necessity in Pascal.

Choosing the division and modulo operators correctly in integer arithmetic prevents silent bugs in algorithms.

Common mistakes

Wrong

program Test;
var
  a, b: Integer;
begin
  a := 5; b := 2;
  if a > 1 and b < 3 then
    writeln('ok');
end.

Because the logical operator has high precedence, the expression tries to combine the two values in the middle first and results in a type mismatch error. Enclosing every comparison in parentheses is mandatory; this is Pascal's best-known pitfall.

Correct

program Test;
var
  a, b: Integer;
begin
  a := 5; b := 2;
  if (a > 1) and (b < 3) then
    writeln('ok');
end.

Wrong

program Test;
var
  a: Integer;
begin
  a := 5;
  if a != 3 then
    writeln('different');
end.

In Pascal, the not-equal operator is written with angle brackets; the exclamation mark format is not valid and causes a syntax error. This is the difference C-family developers encounter on day one.

Correct

program Test;
var
  a: Integer;
begin
  a := 5;
  if a <> 3 then
    writeln('different');
end.

Wrong

program Test;
var
  toplam: Integer;
begin
  toplam := 0;
  toplam++;
  writeln(toplam);
end.

There is no increment operator in Pascal; this code causes a syntax error. To increment the value, an explicit assignment is written or the increment procedure found in some compilers is used. The language prefers clarity over abbreviations.

Correct

program Test;
var
  toplam: Integer;
begin
  toplam := 0;
  toplam := toplam + 1;
  writeln(toplam);
end.

Frequently asked questions

Why do logical operators have high precedence?

Because in Pascal, these operators also perform bitwise operations on integers, and their precedence is defined at the multiplication level. This design heritage appears today as the mandatory use of parentheses in conditions.

Is short-circuit evaluation supported?

It depends on the compiler setting. Free Pascal performs short-circuit evaluation by default, but it can also be switched to full evaluation mode. When writing code that relies on this, you need to check the compiler setting.

How does the modulo operator behave with negative numbers?

The sign of the result follows the sign of the dividend. You need to know this behavior when working with algorithms involving negative values; it may yield a different result from mathematical modular arithmetic.

Summary

The not equal operator is written with angle brackets.

Logical operators are expressed as words.

The precedence of logical operators is higher than comparison.

Parentheses are mandatory in compound conditions.

There is no increment operator.

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