Back to marketplace

Chapter 56 - Subroutines and recursion

No description yet. This curated deck is ready for daily study.

Total cards: 24•Content version: v4•Public deck•Updated: 8/1/2026

Card preview (24)

#1
Front (Question)

What is a subroutine?

Back (Answer)

» A name block of code which performs a specific task within a program

#2
Front (Question)

What are the 2 types of subroutines?

Back (Answer)

» Functions » Procedures

#3
Front (Question)

What is the difference between a function and a procedure?

Back (Answer)

» The function returns a value but the procedure doesn’t » if there are values already in the subroutine, you use a procedure

#4
Front (Question)

How can you call the subroutine from the main program and output it to the user?

Back (Answer)

» Simply write the subroutine name

#5
Front (Question)

What does the first line of a subroutine specify?

Back (Answer)

» The interface for that subroutine

#6
Front (Question)

What is modularity?

Back (Answer)

» Concept of breaking a large program or problem down into smaller chuncks

#7
Front (Question)

What is the benefit of modularity?

Back (Answer)

» Each module carries out a single specific task

#8
Front (Question)

What does a procedure do?

Back (Answer)

» Performs a set task and can take in a zero, 1 or 2 inputs

#9
Front (Question)

What happens when a parameter is passed by a value?

Back (Answer)

» The value created for the subroutine being called is a copy of the original » Held in a separate memory location once passed » It is now a local variable

#10
Front (Question)

What happens if you change the parameter inside the subroutine when you pass a value?

Back (Answer)

» It will not affect its value outside the subroutine

#11
Front (Question)

What does it mean if a parameter is passed by a reference?

Back (Answer)

» The address of the parameter is passed to the subroutine » A pointer that contains the memory address of the original variable is created

#12
Front (Question)

What happens if you change the value in the parameter when passing by a reference?

Back (Answer)

» A change to this value within the called subroutine will also affect the value outside the subroutine » It becomes a global variable

#13
Front (Question)

What does it mean if you say a scope of a variable?

Back (Answer)

» Refers to where a variable is visible or accessible from inside the main program

#14
Front (Question)

What is a global variable?

Back (Answer)

» A variable which is defined in the main program, outside any functions » Has a global scope

#15
Front (Question)

What are some disadvantages of using a global variable?

Back (Answer)

» Needs to be preserved in memory all the time, this means memory space is kept throughout the running of the program » Makes it less memory efficient

#16
Front (Question)

Why do we avoid using global variables?

Back (Answer)

» Increases complexity of the program - as they can be used by many difference parts of the program » Make them harder to keep track of its value » If you want to re-use code, you have to track and remember the value of the global variable

#17
Front (Question)

Why do we used global variables?

Back (Answer)

» To use a variable which can be accessed from any parts of a program » When a value needs to stay the same throughout the program

#18
Front (Question)

What is a local variable?

Back (Answer)

» A variable which is defined in the procedure or function, and can be used only inside that function

#19
Front (Question)

What are the advantages of using a local variable?

Back (Answer)

» Local variables in difference subroutines can have the same identifier » Changing the value of a local variable in a subroutine, will not affect its value outside the subroutine

#20
Front (Question)

What are the disadvantages of using a local variable?

Back (Answer)

» Can overwrite global variables with the same name » Only exists during the execution of the program

#21
Front (Question)

What the principle of encapsulation?

Back (Answer)

» The subroutine written according to this principle can be tested independently, and used in many different programs without the programmer needing to know what variable it uses

#22
Front (Question)

What are the benefits of programming with subroutines?

Back (Answer)

» Relatively easy to understand and debug » Can be tested independently » It can be re-used » Can use a modular approach

#23
Front (Question)

When is a subroutine recursive?

Back (Answer)

» If its defined in terms of tiself

#24
Front (Question)

What is recursion?

Back (Answer)

» When a subroutine calls itself from within its own subroutine