onlinecompiler.io

Pascal online compiler

Write Pascal code below and run it free on Free Pascal 3.2, with no sign-in and no ads. readln reads the Input tab, Turbo Pascal programs with uses crt compile as they are, and {$mode objfpc} or {$mode delphi} turns on classes. The same compiler is an API and an embeddable editor, for running Pascal in your own app, course or docs.

Também em portuguêsTambién en español

Share gives a link, no account needed. Save keeps it in your account.

Run Pascal from your own app, bot or course. One API call returns the output, errors, exit code and run time. Free up to 100,000 runs a month, commercial use included, no card.

Checking a solution against several inputs? The Pascal online compiler with test cases runs them all at once and marks each one passed or failed.

Pascal examples: arrays, functions and records

A class-marks program: readln reads how many marks there are, read takes them from one line, and two functions work out the average and the highest.

program Results;

const
  MaxN = 100;

var
  marks: array[1..MaxN] of integer;
  n, i: integer;

function Average(count: integer): real;
var
  i, total: integer;
begin
  total := 0;
  for i := 1 to count do
    total := total + marks[i];
  Average := total / count;
end;

function Highest(count: integer): integer;
var
  i, best: integer;
begin
  best := marks[1];
  for i := 2 to count do
    if marks[i] > best then
      best := marks[i];
  Highest := best;
end;

begin
  readln(n);
  for i := 1 to n do
    read(marks[i]);
  writeln('Average: ', Average(n):0:2);
  writeln('Highest: ', Highest(n));
end.

With 5 on the first line of the Input tab and 72 85 90 64 88 on the second, it prints Average: 79.80 and Highest: 90.

Records and sorting: each line of the Input tab has a score and a name, and a bubble sort ranks them, highest first. Trim comes from the SysUtils unit.

program Ranking;

uses SysUtils;

type
  TStudent = record
    name: string;
    score: integer;
  end;

var
  s: array[1..50] of TStudent;
  tmp: TStudent;
  n, i, j: integer;

begin
  readln(n);
  for i := 1 to n do
  begin
    read(s[i].score);
    readln(s[i].name);
    s[i].name := Trim(s[i].name);
  end;

  { Sort by score, highest first }
  for i := 1 to n - 1 do
    for j := 1 to n - i do
      if s[j].score < s[j + 1].score then
      begin
        tmp := s[j];
        s[j] := s[j + 1];
        s[j + 1] := tmp;
      end;

  for i := 1 to n do
    writeln(i, '. ', s[i].name, ' (', s[i].score, ')');
end.

With this input:

4
72 Ana
91 Ben
85 Chloe
64 Dev

it prints:

1. Ben (91)
2. Chloe (85)
3. Ana (72)
4. Dev (64)

What runs your code

VersionPascal Free Pascal 3.2
Compiled withfpc -l- -v0ew -O2 code.pas -ocode.out
Run with./code.out
Limits30 seconds, 512 MB of memory (up to 2 GB through the API on Pro and above), 2 CPUs, 64 KB of output per stream, no network
Typical run0.98 s, and 1.34 s for the slowest 1 in 20 (how we measured)

Good to know

  • Compiles with fpc -O2 in Free Pascal's default mode. Add {$mode objfpc}{$H+} or {$mode delphi} for classes and Delphi syntax.
  • readln reads from the Input tab. Without {$H+}, string holds at most 255 characters.
  • Compiler errors and warnings are shown; notes and hints are not.

Pascal compiler API

To run Pascal from your own app, send the code and its input to the sync endpoint with an API key, and the output comes back in the response. It's free up to 100,000 runs a month, with no credit card: get a free API key. The API docs cover the async endpoint with callbacks and every response field.

Terminal
curl -X POST https://api.onlinecompiler.io/api/run-code-sync/ \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "compiler": "fpc-3.2",
    "code": "program Hello;\nvar name: string;\nbegin\n  readln(name);\n  writeln('\''Hello, '\'', name, '\''!'\'');\nend.",
    "input": "Ada"
  }'

The response has output ("Hello, Ada!\n" here), error, exit_code, time and memory.

Embed a Pascal compiler in your website

The editor above is the embeddable widget. Add the script and a div with your widget key, and your readers can edit and run the code without an account:

example.html
<script src="https://onlinecompiler.io/widget.js"></script>

<div class="runcode" data-key="YOUR_WIDGET_KEY" data-lang="fpc-3.2">
  <script type="text/plain">
    program Hello;
    var name: string;
    begin
      readln(name);
      writeln('Hello, ', name, '!');
    end.
  </script>
  <a data-credit href="https://onlinecompiler.io/">Runs on OnlineCompiler.io</a>
</div>

On a platform that takes an iframe but not a script, such as many course sites, use the iframe embed. For Docusaurus, MkDocs, Sphinx and Mintlify, see runnable code examples in docs.

Other languages

Python, C, C++, Java, C#, F#, Go, Rust, PHP, Ruby, Haskell, TypeScript, JavaScript, SQL, DuckDB, Bash, Fortran, Visual Basic, Kotlin, R, Swift, COBOL, Perl, Julia, Octave, Assembly, Lua, OCaml, Common Lisp, Erlang, Elixir, Prolog, D, FreeBASIC, Dart, Clojure, Groovy, Scala, Zig, Nim, Crystal, Ada, PowerShell, Racket, Objective-C.

Frequently asked questions

Is this Pascal online compiler free?

Yes. Running Pascal on this page needs no account and shows no ads. To run Pascal from your own app or site, the API and the widget are free up to 100,000 runs a month, commercial use included.

Is there a Pascal compiler API?

Yes. POST the code, the compiler id fpc-3.2 and any input to https://api.onlinecompiler.io/api/run-code-sync/ with an API key, and the response holds the output, errors, exit code, run time and memory. It's free up to 100,000 runs a month, and the same key works for the other 45 languages.

Can my Pascal program read input?

Yes. Type it in the Input tab before you run, and the program reads it with readln and read, as in Turbo Pascal: readln(a, b) takes two numbers from one line and moves on to the next. The whole input is sent when you press Run, so a program can't ask for more while it runs.

Can I use Pascal libraries?

Free Pascal's runtime library, including SysUtils, Classes, Math and StrUtils. Other units can't be installed, and programs have no network access.

Is this Turbo Pascal, Delphi or Free Pascal?

Free Pascal 3.2. Its default mode runs Turbo Pascal style programs and keeps Turbo Pascal's 16-bit integer, so integer stops at 32767; use longint for larger numbers. For Delphi code, with classes and Result, put {$mode delphi} at the top, or {$mode objfpc}{$H+} for the Lazarus style, where integer is 32-bit.

Does Turbo Pascal's uses crt work?

Yes. Programs with uses crt compile and run: clrscr, textcolor, gotoxy and delay work, but colours and screen positions don't show, since the output is plain text. readkey reads the next character from the Input tab.

Why do I get "Duplicate identifier"?

Pascal ignores case, so a program called Marks can't also have a variable called marks. Rename one of them.

How do I read several numbers from one line?

read(x) reads the next number wherever it is, so read(a, b, c) takes three numbers from one line, and readln moves on to the next line, as in the marks example above.

Can I share or save my code?

Yes. Share gives you a link that anyone can open and run, lasts 90 days and needs no account. Save keeps the code in your OnlineCompiler.io account until you delete it. When you are signed in, each run you make on this page is also kept in your account's run history.

How long can a program run?

Up to 30 seconds, with 512 MB of memory (up to 2 GB through the API on Pro and above) and 2 CPUs. A program still running at 30 seconds is stopped with exit code 124, and output over 64 KB per stream is cut.

Where does my code run?

On our servers, in a fresh gVisor sandbox with no network access that is deleted when the run ends. Each run is kept in execution history with its output; the security page says what is stored.