FINAL | Subprograms | PROGLANG

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

1/73

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 3:47 PM on 5/25/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

74 Terms

1
New cards

Subprogram

It is a named, self-contained block of code designed to execute a specific task within a larger program.

2
New cards

functions, procedures, or methods

It is also known as f___________, p___________, or m__________(depending on the language).

3
New cards

Subprogram

It allows programmers to group logically related operations and execute them whenever needed.

4
New cards

def

Subprograms are declared using the d___ keyword followed by a function name, a parameter list, and a block of statements.

5
New cards

Subprogram

These are fundamental constructs in all modern programming languages.

6
New cards

divide-and-conquer

Subprograms support the d_______ and c__________ approach by allowing a program to be decomposed into manageable units, which improves clarity, debugging, collaboration, and reuse.

7
New cards

Modularity

The main purpose of subprograms is to promote m__________.

8
New cards

Modularity

It is the process of breaking down a program into smaller, functional components.

9
New cards

understand and maintain

Code is easier to u__________ and m__________ because each subprogram handles a specific task.

10
New cards

once

Redundancy is reduced since frequently used operations can be written o____ and called many times.

11
New cards

isolated and verified

Testing and debugging are more efficient, as subprograms can be i__________ and v_______ independently.

12
New cards

smoother

Collaboration becomes s__________ since development teams can assign different subprograms to different members.

13
New cards

Mathematical Computation

Subprograms for operations like finding the square root, computing factorials, or evaluating mathematical expressions.

14
New cards

Data Handling

Functions for data validation, parsing, formatting, and transformation.

15
New cards

User Interface (UI)

Subprograms that handle events like button clicks, form submissions, or rendering interface components.

16
New cards

Web Development

Backend functions to process requests, interact with databases, and return responses to the user.

17
New cards

Software Application Programming Interface (API)

Subprograms expose functionality for external programs to reuse, like authentication, logging, or payment processing.

18
New cards

Game Development

Control mechanics such as character movement, score tracking, and level progression are often subprogram-based.

19
New cards

functions

Subprograms are implemented primarily through f_________.

20
New cards

value, arguments

Subprograms may or may not return v______ and can accept various a__________, including default, keyword, and variable-length parameters.

21
New cards

Parameter passing

It determines how arguments are transmitted from the caller to the subprogram.

22
New cards

Parameter passing

It affects whether modifications made inside the subprogram reflect outside and influences memory management and performance.

23
New cards

Pass-by-object-reference

Python uses a mechanism called "pass-by-object-reference" (a mix of pass-by-value and pass-by-reference depending on mutability).

24
New cards

Pass-by-Value

Copies the value of the actual parameter. Changes in the function do not affect the original.

25
New cards

Pass-by-Value

Simulated with immutable types

26
New cards

Pass-by-Reference

Passes a reference (address) of the argument. Changes affect the original.

27
New cards

Pass-by-Reference

Simulated with mutable types

28
New cards

Pass-by-Result

A parameter acts like a placeholder to be filled with a result and returned.

29
New cards

Pass-by-Result

Not directly supported

30
New cards

Pass-by-Value-Result

Value is copied in, and the result is copied out after function execution.

31
New cards

Pass-by-Value-Result

Not natively supported

32
New cards

Pass-by-Value

Demonstrates that changes to parameters inside the function do not affect the original variable.

33
New cards

original data

Pass-by-Value is useful when protecting the o________ d_____ from unintended side effects.

34
New cards

immutable

Python integers are i____________, so num inside the function is a copy of x's value. This mimics pass-by-value.

35
New cards

Pass-by-Reference

Demonstrates how changes to a parameter inside a function affect the original variable when the parameter is mutable.

36
New cards

lists or dictionaries

Pass-by-Reference is useful for modifying data structures like l____ or d___________.

37
New cards

mutable

Since lists are m_________, Python passes a reference to the list, so operations inside the function apply to the original data.

38
New cards

Pass-by-Result (Simulated)

Illustrates how a function might assign a result to an initially empty or placeholder variable and return it. While Python does not support true pass-by-result, the behavior can be simulated by returning the result explicitly.

39
New cards

Pass-by-Value-Result (Simulated)

Mimics is a mechanism where a copy of the value is passed into the function, modified internally, and the updated result is explicitly returned and reassigned to the original.

40
New cards

reassigned

Pass-by-Value-Result (Simulated) is suitable when internal processing should not affect the original unless explicitly r_________.

41
New cards

Yes

Does Pass-by-Value support data protection?

42
New cards

No

Does Pass-by-Value allow data mutation?

43
New cards

original variables

Pass-by-Value Use Case: Protect o________ v___________

44
New cards

No

Does Pass-by-Reference support data protection?

45
New cards

Yes

Does Pass-by-Reference allow data mutation?

46
New cards

place

Pass-by-Reference Use Case: Modify caller’s data in p______

47
New cards

Yes

Does Pass-by-Result support data protection?

48
New cards

Yes (output only)

Does Pass-by-Result allow data mutation?

49
New cards

generated or computed

Pass-by-Result Use Case: Return g___________ or c___________ results

50
New cards

Yes (initially)

Does Pass-by-Value-Result support data protection?

51
New cards

Yes (reassigned)

Does Pass-by-Value-Result allow data mutation?

52
New cards

side-effects

Pass-by-Value-Result Use Case: Controlled s___ e_______

53
New cards

Call stack

When a subprogram is called, it must allocate memory to store its local variables, parameters, return address, and bookkeeping information. This allocation typically occurs in a region of memory called the c____ s______.

54
New cards

Call stack

is a system-managed data structure that tracks active subprogram calls during execution. activation record (or stack frame)

55
New cards

Stack Frame

Another term for activation record.

56
New cards

Parameter, Local Variable, Return Address

An activation record includes the following:

57
New cards

Parameters

These are passed to the subprogram

58
New cards

Local variables

These are declared inside the subprogram

59
New cards

Return address

(where to resume after the subprogram ends)

60
New cards

popped

When the subprogram completes, its activation record is p________ from the stack, and all memory associated with it is released.

61
New cards

Static Allocation and Stack-Dynamic Allocation

There are two (2) primary strategies for allocating local variables:

62
New cards

when and how

Static Allocation and Stack-Dynamic Allocation affect w___ and h____ long variables exist in memory and how subprograms can reuse or preserve data across multiple calls.

63
New cards

Stack-Dynamic Variables

These are local variables allocated at runtime when the subprogram is called.

64
New cards

execution

Stack-Dynamic Variables memory exists only during the e________ of that specific call. Once the subprogram returns, the variables are discarded, and subsequent calls will reinitialize them.

65
New cards

Stack-Dynamic Variables

This behavior is the default in Python and most modern programming languages.

66
New cards

recursion and concurrent

Stack-Dynamic Variables allows each call to a subprogram to have its own independent set of variables, which is essential for r_________ and c_________ function execution.

67
New cards

Memory Management

Automatic deallocation of local variables prevents memory leaks.

68
New cards

Recursion

Recursive functions rely on the stack to track each invocation's local state.

69
New cards

Data Isolation

Variables in different calls do not interfere with each other unless passed explicitly.

70
New cards

Performance

Stack allocation is fast due to the last-in, first-out (LIFO) nature of the call stack.

71
New cards

Static-Dynamic Variables

These are allocated once and persist across all calls.

72
New cards

fixed memory location

Static-Dynamic Variables reside in a f______ m__________ l____________ and retain their values between subprogram invocations.

73
New cards

function calls or caching results

Static-Dynamic Variables is useful for counting f_________ c_____ or c_______ r________ but risks unintended side effects in multithreaded or recursive environments.

74
New cards

multithreaded or recursive

Static-Dynamic Variables can have unintended side effects in m___________ or r____________ environments