Defining a function
function Square(x: integer): integer;
begin
Square := x * x;
end;
begin
writeln(Square(5));
end.
A function's name is declared with its parameter and return types; inside the body, assigning to the function's own name (Square := ...) is how it returns a value.
Procedures
A procedure is like a function but returns nothing:
procedure Greet(name: string);
begin
writeln('Hello, ', name, '!');
end;
begin
Greet('Ada');
end.
Arrays
An array is a fixed-size, ordered collection -- its size is part of its declared type:
var
fruits: array[0..2] of string;
begin
fruits[0] := 'apple';
fruits[1] := 'banana';
fruits[2] := 'cherry';
writeln(fruits[0]); { apple -- indexing starts at 0 }
writeln(length(fruits)); { 3 }
end.
Looping over an array
var
i: integer;
begin
for i := 0 to length(fruits) - 1 do
writeln(fruits[i]);
end.
Why This Matters for Your Exams
Unlike a Python list, a Pascal array's size is fixed at declaration -- there's no .append(). Reaching for an index past the declared bound is a runtime error, not a silent resize, so always declare arrays large enough for what you'll store in them.
Try it yourself
lock
Real-time practice is a paid add-on
Reading units and the practice quiz are free. Pay once to unlock running real code for PASCAL.

