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 is also changed in the same way.

The Experiment:

The current definition of main() follows this 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 if the function's changes make any difference outside the function.

Observation:

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

Conclusions:

Question #8.2.2: Is our hypothesis correct? How do you know? If it's not correct, what should it be?

Question #8.2.3: How might the definition of a value parameter given you a clue about this experiment?


Back to the Lab Exercise  |  Forward to the Next Experiment
© 2003 by Prentice Hall. All rights reserved.
Report all errors to Jeremy D. Frens.