[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
Parameters Values Passed to Subprograms
Both types of subprograms--procedures and functions--can optionally
have a list of parameters. These are values and variables passed to
the subprogram; the subprogram can then use and modify these
parameters. The parameters declared in the subprogram header are known
as FORMAL (or dummy) parameters. Those listed in an actual call to the
subprogram are known as ACTUAL parameters. The number and type of
actual parameters must always match the formal parameters.
The general syntax for a parameter list is:
(<parm decl>; <parm decl>; ...; <parm decl>)
The <parm decl>, in turn, takes the form
var <names> : <type>
where the keyword VAR is optional, <names> is a list of one or more
legal identifiers (separated by commas), and <type> is any defined
data type.
If you start a <parm decl> with the keyword VAR, then you are saying
that the parameters in that declaration are PASS BY ADDRESS, which
means that (1) the corresponding actual parameters must be variables,
and (2) that any changes made to the formal parameters will also be
made to the actual parameters.
If you omit the keyword VAR, then the parameters are PASS BY VALUE.
This means that the actual parameters can also be constants,
expressions, or function calls--in short, anything that yields a value
of the appropriate type. Also, any changes made to the formal
parameter do not affect or change the actual parameter.
The <names> must be legal identifiers. They can be the same as
identifiers declared outside of the subprogram. If this is the case,
they supersede those external parameters, which cannot then be
referenced within the subprogram.
The <type> can be any predefined data type (Integer, Real, Char,
Boolean, text) or any data type declared in the TYPE section of the
enclosing program and subprograms (if any). Standard Pascal also
allows procedures and functions to be passed as parameters. Turbo
Pascal, however, does not. Finally, any parameters of a file type must
be passed by address.
You can't directly declare arrays, records, sets, files, or enumerated
data types in <type>; instead, these must be defined as a data type
and that identifier used in the parameter list. For example, the
parameter list
procedure Dummy(L : array[1..10] of Integer);
is illegal; the correct approach is:
type
List = array[1..10] of Integer;
...
procedure Dummy(L : List);
See Also:
subprograms
procedures
functions
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson