Modularity, functions and procedures, parameter passing by value and by reference.
2.2.1 Programming Techniques
Programming Techniques — Note 4 of 6
Candidates need to understand what is meant by modular code and how it is produced using functions and procedures, including the differences between them. Candidates need to understand the purpose of parameters and the difference between passing by value and by reference, recommending which to use for a given situation. Candidates need to be able to read, trace and write code that uses functions, procedures and parameters.
Modular programs are built from subroutines, each carrying out one task. Functions return a value; procedures do not. Parameters can be passed by value (a copy) or by reference (the original), which affects whether the subroutine can change the caller's data.
Exam tipCommon mistake
Breaking a program into separate subroutines or modules, each performing one task, that can be written and tested independently.
A subroutine that returns a value to the point where it was called.
A subroutine that carries out a task but does not return a value.
A variable in the subroutine definition that receives a value (argument) when the subroutine is called.
byVal and byRef are used.A COPY of the argument is passed; changes inside the subroutine do not affect the original variable.
The ADDRESS of the original variable is passed; changes inside the subroutine DO affect the original variable.
procedure update(x:byVal, y:byRef)
x = x + 10
y = y + 10
endprocedure
a = 1
b = 1
update(a, b)
print(a) // 1 (only the copy changed)
print(b) // 11 (the original changed)