Page 111: Short Answer
1) How do modules help you to reuse code in a program?
A. MODULES ALSO REDUCE THE DUPLICATION OF CODE WITHIN A PROGRAM.THIS BENEFIT OF USING MODULES IS KNOWN AS CODE REUSE BECAUSE YOU ARE WRITING THE CODE TO PERFORM A TASK ONCE AND THEN REUSING IT EACH TIME YOU NEED TO PERFORM A TASK.
2) Name and describe the two parts that a module definition has in most languages.
A. Header –Starting point of the module
Body-List of statements that belong to the module
3) When a module is executing, what happens when the end of the module is reached?
A. When a module is called, the computer jumps to that module and executes the statement in the module's body. Then, when the end of the module is reached, the computer jumps back to the part of the program that called the module, and the program resumes execution at that point.
4) What is a local variable? What statements are able to access a local variable?
A. A local variable is a variable that can only be called on by the module. Whereas a global variable can be called upon by any module. Only statements made inside the same module can call on a local variable.
5) In most languages, where does a local variable’s scope begin and end?
A. A local variable’s scope usually begins at the variable’s declaration and ends at the end of the module in which the variable is declared.
6) What is the difference between passing an argument by value and passing it by reference?
A. Pass by Reference:
In Pass by reference address of the variable is passed to a function. Whatever changes made to the formal parameter will affect to the actual parameters
- Same memory location is used for both variables. (Formal and Actual)-
- it is useful when you required returning more than 1 value
Pass by Value:
- In this method value of the variable is passed. Changes made to formal will not affect the actual parameters.
- Different memory locations will be created for both...