Unit 4 Assignment 1 Homework

808 Words4 Pages
Unit 4 Homework PT 1420 Brian Clear 6 April 2014 Unit 4 Assignment 1: Homework Short Answer 1. How do modules help you to reuse code in a program? Modules allow the programmer to write an operation once and then be executed any time it is needed. 2. Name and describe the two parts that a module definition has in most languages. Header: The starting point of the module. Body: The list of statements that belong to the module. 3. When a module is executing, what happens when the end of the module is reached? The program returns to the memory address just after from where the module was called, and continues to execute. 4. What is a local variable? What statements are able to access a local variable? A local variable is a variable that is declared from within the module. Only statements in that module can access it. 5. In most languages, where does a local variable’s scope begin and end? A local variable’s scope 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? Passing an argument by value is a one-way communication from the main program to the module. Changes to the parameter variable inside the module do not effect the argument in the calling part of the program. Passing an argument by reference is a two-way communication between the module and the main program which allows the module to modify the argument in the calling part of the program. 7. Why do global variables make a program difficult to debug? Any statement in a program can change the value of a global variable. To find where a bad value is coming from, a programmer would have to track down every statement that has access to that variable. Algorithm Workbench 1. Design a module named timesTen. The module should
Open Document