< previous page page_375 next page >

Page 375
ble only within the block in which they are declared. Local variables must be initialized each time the function containing them is called because their values are destroyed when the function returns.
You may call functions from more than one place in a program. The positional matching mechanism allows the use of different variables as actual parameters to the same function. Multiple calls to a function, from different places and with different actual parameters, can be used to simplify greatly the coding of many complex programs.
Quick Check
1. If a design has one Level 0 module and three Level 1 modules, how many C++ functions is the program likely to have? (pp. 324328)
2. Does a C++ function have to be declared before it can be used in a function call? (p.328)
3. What is the difference between a function declaration and a function definition in C++?(pp. 335338)
4. Given the function heading
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
void QuickCheck( int    size,
                 float& length,
                 char   initial )
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
indicate which parameters are value parameters and which are reference parameters. (pp. 342343)
5. a. What would a call to the QuickCheck function look like if the actual parameters were the variables radius (a float), number (an int), and letter (a char)? (p.334)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. How is the matchup between these actual parameters and the formal parameters made? What information is actually passed from the calling code to the QuickCheck function, given these actual parameters? (pp. 342350)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. Which of these actual parameters is (are) protected from being changed by the QuickCheck function? (pp. 342350)
6. Where in a function are local variables declared, and what are their initial values equal to? (pp. 338339)
7. Assume that you are designing a program and you need a void function that reads any number of floating point values and returns their average. The number of values to be read is in an integer variable named dataPoints, declared in the calling code.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. How many parameters will there be in the formal parameter list, and what will their data type(s) be? (pp. 352354)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Which of the formal parameters should be passed by reference and which should be passed by value? (pp. 352354)
8. Describe one way in which you can use a function to simplify the coding of an algorithm. (pp. 333334)
Answers 1. Four (including main) 2. Yes 3. A definition is a declaration that includes the function body. 4. length is a reference parameter; size and initial are value parameters. 5. a. QuickCheck (number, radius, letter); b. The matchup is done on the basis of the pa-

 
< previous page page_375 next page >