Please enable JavaScript.
Coggle requires JavaScript to display documents.
Procedures and Functions - Coggle Diagram
Procedures and Functions
Benefits of using procedures and functions in a program
Procedure code and be saved and re-used in future projects by creating a module library.
The repetition of lines of code is avoided.
Testing of the procedure code can take place in isolation from the main program.
Debugging of the main program is simplified as each procedure can be individually tested.
description of a procedure.
They are activated by a call from the main program. When a procedure is called it produces an effect.
description of a function.
A function is activated by a call from the main program. A function returns a single value.
The differences between a procedure and function.
The difference between a procedure and a function is a function returns a value and a procedure creates an effect.
description of a local and a global variable and explain the scope of these
Local variables are created when the subroutine is called and are then destroyed when the subroutine terminates.
For a local variable the scope is limited to a single procedure or function.
A global variable can be accessed and altered from any part of the program, even from another script/event so long as it is declared at the very start.
For a global variable the variable is visible throughout the whole program. This means the scope is the whole program.
description of a formal parameter
A formal parameter is used as a placeholder within a subprogram for the values received or sent to the main program’s actual parameters.
description of an actual parameter
An actual parameter is the actual value that is passed into the procedure.
description of by reference and by value
By Value: The subroutine will be passed a copy of the original parameter, so that the original parameter remains unchanged.
By Reference: The subroutine will be passed the original parameter and any changes made in the subroutine will result in a change to the original value(s) held within the parameter.
why we use by reference when passing an array regardless of whether or not it is changing
we use reference when passing an array to save memory because arrays can store a lot of information therefore storing a lot of memory