Karteikarten
Modularity/ Subroutines
Karten in diesem Stapel (20)
- 1What is a module (subroutine)?A set of instructions with a name. They can be called upon by the main body of code to complete a task. A module (subroutines) can be created using a function or a procedure.
- 2What is a procedure?A block of code that is given a name. When called from the main code, it will complete a task and then hand control back over to the main code, They may have parameters passed to them but they DO NOT return a value?
- 3What happens if a function is acting as a procedure?The output is declared as void
- 4What do you need to define a procedure?- procedure name
- any parameters needed
- the processing code itself - 5What is the procedure structure?procedure name (x,y)
code......
endprocedure - 6What is a function?A block of code that is given a name. When called from the main code, it will complete a task and then hand control back over to the main code. They may have parameters passed to them and they DO return a value back to the main code.
- 7How does a function work?- program comes to a line of code containing a function call
- program will then pass control to the function
- code inside the function is executed from the beginning to the end (unless there is a break statement)
control is then passed back to the main body to the line containing the function call
- Any data returned by the function is used in place of the function in the og line of code. - 8What things do we need to define a function?- function name
- parameters needed
- the code itself
- the output - 9How do you structure a function?function name (x,y)
code......
return x
endfunction - 10What are some examples of built-in functions?- input()
- print ()
- min ()
-max () - 11Benefits of subroutines?- large programs are broken down that are easier to program/manage
- modules can be individually tested/debugged
- modules can be re-used saving development and testing time
- several programmers can work on different modules, shortening development time
- frequently used modules can be stored in a library and used by other programs
- self contained modules that are changed should not affect the rest of the program - 12What is a parameter?Piece of data that is input into a function or a procedure. A parameter can either be passed by value or by reference
- 13What are the two ways a parameter can be passed?By reference or by value
- 14What does by reference mean?The function receives the memory location of where the data/variable is stored. This means that while the function is being executed it will work with the original data stored in the variable.
It will overwrite the data in the variable
The changes will remain after the function exits - 15What are the benefits of by reference?- Makes use of existing memory so does not need additional memory
- ideal if global variables are needed or if the value does not need editing - 16What are the risks of by reference?- sends a pointer to the value in the memory (the actual value is not sent). Therefore the original data is also changed when the subroutine ends.
- can cause problems if the data has changed/ is being used by another program - 17What is by value?If a parameter is passed by value, the function receives a copy of the data/ variable.
This means that while the function is being executed it will work with the copy of the data stored in the variable.
Any changed made are lost as soon as the function is no longer in use therefore it does not overwrite the og data/variable. - 18What are the benefits of by value?- sends a copy of the value, therefore any changes are lost as soon as subroutine is no longer in use.
- ideal if only local variables are needed or if the value does not need editing
- ensures that the data does not have an unintended effect on the rest of the code - 19What are the risks of by value?- creates new memory space, requires additional memory
- 20in the exam, are they by value or by reference?unless otherwise stated, parameters are passed as by value
Informationen
- Beschreibung
- A level Computer Science (Unit 2 - Topic 2) Karteikarten am Modularity/ Subroutines, erstellt von Ariana Parr am 17/02/2022.
- Erstellt von
- Ariana Parr · Feb 2022
- Aktualisiert
- 17 Feb 2022
- Aufrufe
- 0
- Bewertung