function
Try it yourself →Subroutine that returns a value.
Syntax
function name(x: Type): Type; begin name := ...; end;
Description
The return value is assigned to the function's NAME. Defined before begin.
Example
program H; function square(x: integer): integer; begin square := x * x; end; begin writeln(square(5)); end.
Expected output
25
When to use?
Preventing code repetition.
Common mistakes
- ⚠️ The return value is assigned to the function name: square := x*x; (no return).