Lab 8: Experiment 2

Value Parameters and Their Arguments

Issue: If a function alters the value of one of its value parameters, what is the effect on the argument corresponding to that parameter?

Hypothesis: When a value parameter is changed, the corresponding argument is also changed in the same way.

The Experiment:

The current version of main() in params.cpp implements the following algorithm:

  1. Assign initial values to arg1, arg2, and arg3.
  2. Display the values of arg1, arg2, and arg3.
  3. Call change(), passing it arg1, arg2, and arg3.
  4. Display the values of arg1, arg2, and arg3.
In that third step, change() tries to alter the values of its parameters. Does that affect the variables declared in the main program?

By comparing the values displayed before the function call with those displayed after the function call, we can see whether changes within a function make any difference outside the function.

Observation:

Question #8.2.1: Compile and execute your program. What does it output?

Conclusions:

Question #8.2.2: Is our hypothesis correct? If not, what should it be?

Question #8.2.3: Review the definition of a value parameter at the beginning of Part I of this lab exercise. What key word(s) in this definition give a clue about what the outcome of this experiment would be?


Back to the Lab Exercise  |  Forward to the Next Experiment


Report errors to Larry Nyhoff (nyhl@cs.calvin.edu)