Modules Flashcards
What is a module in programming?
A group of statements that perform a specific task within a program.
What is the purpose of dividing a program into smaller modules?
To divide and conquer large tasks, making them manageable.
List three benefits of using modules in programming.
Simpler code, code reuse, easier maintenance.
What is the recommended type of name for a module?
Descriptive names using verbs to indicate actions, e.g., calculateGrossPay.
What are the two parts of a module definition?
A header and a body.
Where does a program begin executing?
In the main module.
What is a return point in module calling?
A memory location where the program returns after a module call.
What shape is used to represent a module call in a flowchart?
A rectangle with vertical bars at each side.
What is the goal of top-down design?
To break down a task into subtasks and code after identifying them.
What does a hierarchy chart represent?
The relationships between modules in a program.
Where can a local variable be accessed?
Only inside the module in which it is declared.
What happens if two variables have the same name but are declared in different scopes?
They are treated as separate variables.
What is the scope of a variable?
The part of a program where a variable can be accessed, starting from its declaration to the end of its module.
What is an argument in a module?
Data passed into a module when it is called.
What is the role of a parameter in a module?
To store the argument passed into the module.
What happens if an argument and a parameter have mismatched data types?
An error occurs.
What is the scope of a parameter variable?
The entire module where it is declared.
What is the difference between passing arguments by value and by reference?
By value: The parameter gets a copy of the argument, with no effect on the original variable.
By reference: The parameter acts as an alias, allowing changes to affect the original variable.
What is a global variable?
A variable declared outside of all modules and accessible by all modules.
Why should the use of global variables be limited?
They can make debugging and understanding the program difficult.
What are the benefits of using global constants instead of global variables?
Global constants can’t be changed during runtime, reducing hazards associated with global variables.