1/10
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is meant by subroutine?
A named block of code which performs a specific task within a program.
What are two types of subroutines?
Functions
Procedures
What is a function?
A subroutine that returns data.
What is a procedure?
A subroutine that does not return data.
What are two ways for passing parameters?
By value
By reference
What is meant by passing a parameter by value?
Changing the parameter inside the subroutine will not affect its value outside the subroutine. The contents of the parameter you are passing gets copied into the local variable inside the subroutine.
What is meant by passing a parameter by reference?
Changing the parameter inside the subroutine will affect its value outside the subroutine. No copies are made, the variable in the subroutine simply refers to the same piece of memory as the parameter passed in.
What are global variables?
Variables that can be used anywhere in the program.
What are local variables?
Only exist within the lifetime of the scope and can not be accessed outside that scope.
What are the advantages of using local variables?
It ensures that each subroutine is completely self-contained and independent of any global variables that have been declared in the main program.
What are the advantages of using subroutines in a program?
Subroutines can be tested independently. shortening the time to get a large program working
Once a subroutine has be thoroughly tested, it can be reused with confidence in different programs or parts of the same program
Each programmer can be given a specific set of subroutines to work on. This enables the whole program to be finished sooner
A large project becomes easier to monitor and control
A subroutine is small enough to be understandable as a unit of code, so it is relatively easy to understand, debug and maintain.