Procedures accept data to work
 

Procedures may also accept variables (data) to work with when they are called.

Declaring the variables within the procedure


  • The variables accepted by the procedure are enclosed using parenthesis.
  • The declaration of the accepted variables occurs between the procedure name and the terminating semi-colon.

Calling the procedure and Passing variables (or values) to it


  • When the procedure is invoked, the procedure name is followed by a set of parenthesis.
  • The variables to be passed are written inside the parenthesis.
  • The variables are written in the same order as specified in the procedure.

Consider the following program example,


program ADD_NUMBERS (input, output);

procedure CALC_ANSWER ( first, second : integer );
var result : integer;
begin
result := first + second;
writeln('Answer is ', result )
end;

var number1, number2 : integer;
begin
writeln('Please enter two numbers to add together');
readln( number1, number2 );
CALC_ANSWER( number1, number2)
end.

(c) Shilpa Sayura Foundation 2006-2017