Functions and Procedures
Functions and Procedures
Functions and Procedures
and PROCEDURES
(Subroutines)
What is a subroutine?
• Computer programs can consist of thousands of lines of code.
(Just like a text book can have thousands of words).
• Program is divided into related functionality using modules
(In the same way that the text book is divided into chapters).
• In a computer program, specific functionality is divided up into
subroutines.
The <identifier> is the identifier used to call the procedure. Where used,
param1, param2, etc. are identifiers for the parameters of the procedure.
These will be used as variables in the statements of the procedure.
Argument is the actual value of this variable that gets passed to procedure/function.
Parameters
CALL <identifier> (V1, V2)
Arguments
CALLING A FUNCTION:
<identifier> <Function Name>(value1,value2…..)
Because a function returns a value that is used when the function is called, function calls are not
complete program statements. The keyword CALL should not be used when calling a function.
Functions should only be called as part of an expression.
Questions
1. Write a pseudocode to enter 2 subject marks in main program and pass them into CalculateAvg()
function to calculate the average and output the average within the main program.