1/73
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Subprogram
It is a named, self-contained block of code designed to execute a specific task within a larger program.
functions, procedures, or methods
It is also known as f___________, p___________, or m__________(depending on the language).
Subprogram
It allows programmers to group logically related operations and execute them whenever needed.
def
Subprograms are declared using the d___ keyword followed by a function name, a parameter list, and a block of statements.
Subprogram
These are fundamental constructs in all modern programming languages.
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.
Modularity
The main purpose of subprograms is to promote m__________.
Modularity
It is the process of breaking down a program into smaller, functional components.
understand and maintain
Code is easier to u__________ and m__________ because each subprogram handles a specific task.
once
Redundancy is reduced since frequently used operations can be written o____ and called many times.
isolated and verified
Testing and debugging are more efficient, as subprograms can be i__________ and v_______ independently.
smoother
Collaboration becomes s__________ since development teams can assign different subprograms to different members.
Mathematical Computation
Subprograms for operations like finding the square root, computing factorials, or evaluating mathematical expressions.
Data Handling
Functions for data validation, parsing, formatting, and transformation.
User Interface (UI)
Subprograms that handle events like button clicks, form submissions, or rendering interface components.
Web Development
Backend functions to process requests, interact with databases, and return responses to the user.
Software Application Programming Interface (API)
Subprograms expose functionality for external programs to reuse, like authentication, logging, or payment processing.
Game Development
Control mechanics such as character movement, score tracking, and level progression are often subprogram-based.
functions
Subprograms are implemented primarily through f_________.
value, arguments
Subprograms may or may not return v______ and can accept various a__________, including default, keyword, and variable-length parameters.
Parameter passing
It determines how arguments are transmitted from the caller to the subprogram.
Parameter passing
It affects whether modifications made inside the subprogram reflect outside and influences memory management and performance.
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).
Pass-by-Value
Copies the value of the actual parameter. Changes in the function do not affect the original.
Pass-by-Value
Simulated with immutable types
Pass-by-Reference
Passes a reference (address) of the argument. Changes affect the original.
Pass-by-Reference
Simulated with mutable types
Pass-by-Result
A parameter acts like a placeholder to be filled with a result and returned.
Pass-by-Result
Not directly supported
Pass-by-Value-Result
Value is copied in, and the result is copied out after function execution.
Pass-by-Value-Result
Not natively supported
Pass-by-Value
Demonstrates that changes to parameters inside the function do not affect the original variable.
original data
Pass-by-Value is useful when protecting the o________ d_____ from unintended side effects.
immutable
Python integers are i____________, so num inside the function is a copy of x's value. This mimics pass-by-value.
Pass-by-Reference
Demonstrates how changes to a parameter inside a function affect the original variable when the parameter is mutable.
lists or dictionaries
Pass-by-Reference is useful for modifying data structures like l____ or d___________.
mutable
Since lists are m_________, Python passes a reference to the list, so operations inside the function apply to the original data.
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.
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.
reassigned
Pass-by-Value-Result (Simulated) is suitable when internal processing should not affect the original unless explicitly r_________.
Yes
Does Pass-by-Value support data protection?
No
Does Pass-by-Value allow data mutation?
original variables
Pass-by-Value Use Case: Protect o________ v___________
No
Does Pass-by-Reference support data protection?
Yes
Does Pass-by-Reference allow data mutation?
place
Pass-by-Reference Use Case: Modify caller’s data in p______
Yes
Does Pass-by-Result support data protection?
Yes (output only)
Does Pass-by-Result allow data mutation?
generated or computed
Pass-by-Result Use Case: Return g___________ or c___________ results
Yes (initially)
Does Pass-by-Value-Result support data protection?
Yes (reassigned)
Does Pass-by-Value-Result allow data mutation?
side-effects
Pass-by-Value-Result Use Case: Controlled s___ e_______
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______.
Call stack
is a system-managed data structure that tracks active subprogram calls during execution. activation record (or stack frame)
Stack Frame
Another term for activation record.
Parameter, Local Variable, Return Address
An activation record includes the following:
Parameters
These are passed to the subprogram
Local variables
These are declared inside the subprogram
Return address
(where to resume after the subprogram ends)
popped
When the subprogram completes, its activation record is p________ from the stack, and all memory associated with it is released.
Static Allocation and Stack-Dynamic Allocation
There are two (2) primary strategies for allocating local variables:
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.
Stack-Dynamic Variables
These are local variables allocated at runtime when the subprogram is called.
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.
Stack-Dynamic Variables
This behavior is the default in Python and most modern programming languages.
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.
Memory Management
Automatic deallocation of local variables prevents memory leaks.
Recursion
Recursive functions rely on the stack to track each invocation's local state.
Data Isolation
Variables in different calls do not interfere with each other unless passed explicitly.
Performance
Stack allocation is fast due to the last-in, first-out (LIFO) nature of the call stack.
Static-Dynamic Variables
These are allocated once and persist across all calls.
fixed memory location
Static-Dynamic Variables reside in a f______ m__________ l____________ and retain their values between subprogram invocations.
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.
multithreaded or recursive
Static-Dynamic Variables can have unintended side effects in m___________ or r____________ environments