Parameters in Pascal are the variables passed to a function or procedure. We use parameters to pass data we want to use in a function or procedure. There are four types of parameters in Pascal:
Untyped parameters are parameters that have no type. Variable
, constant
, and out
parameters can also be untyped.
Untyped parameters are passed to a function, as follows:
function (_parameterType_ _parameterName_): _returnType_;
begin
//function body
end
Similarly, untyped parameters are passed to a procedure, as follows:
procedure (_parameterType_ _parameterName_);
begin
//procedure body
end
_parameterType_
: The type of the parameter. It can be var
for variable parameter, const
for constant parameter, or out
for out parameter._parameterName_
: The name of the untyped parameter._returnType_
: The data type of the return value of the function.Note:
- The address of the untyped parameter is passed to the function/procedure.
- The function/procedure does not know the data type of the untyped parameter.
- An untyped parameter must be typecasted to use in an assignment or assign a value to it.
Consider the code snippet below, which demonstrates the use of the untyped parameters.
program function1; var a, b, calSum : Integer; function sum(const a, b): Integer; var a2, b2 : Integer; begin a2 := Integer(a); b2 := Integer(b); sum := a2 + b2;;//store return value in variable having same name as the name of function end; begin a := 5; b := 10; writeln(''); calSum := sum(a, b); writeln(a, ' + ', b, ' = ', calSum); end.
A function sum()
is declared in line 5 that calculates the sum of two numbers passed to it as parameters. The parameters passed to the sum()
function are untyped parameters. The untyped parameters a
and b
are typecasted to integers in line 9 and line 10 respectively. After typecasting, the sum is calculated and returned.
RELATED TAGS
CONTRIBUTOR
View all Courses