1.5 - Subroutines

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/10

Last updated 1:58 PM on 6/9/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

11 Terms

1
New cards

What is meant by subroutine?

A named block of code which performs a specific task within a program.

2
New cards

What are two types of subroutines?

  • Functions

  • Procedures

3
New cards

What is a function?

A subroutine that returns data.

4
New cards

What is a procedure?

A subroutine that does not return data.

5
New cards

What are two ways for passing parameters?

  • By value

  • By reference

6
New cards

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.

7
New cards

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.

8
New cards

What are global variables?

Variables that can be used anywhere in the program.

9
New cards

What are local variables?

Only exist within the lifetime of the scope and can not be accessed outside that scope.

10
New cards

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.

11
New cards

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.