Lab 8: Experiment 3

Variable Parameters and Identical Argument Names

The Issue: If a value parameter has the same name as its corresponding argument, will altering the parameter alter the corresponding argument?

Hypothesis: You try this one:

Question #8.3.1: What hypothesis do you want to try to prove? Will the same names make a difference or not?

The Experiment: Modify the definition of change(), so that its parameter-names match the argument names:

void change(int arg1, int arg2, int arg3)
    arg1 = 1;
    arg2 = 2;
    arg3 = 3;

This function is already called in the main program with the statement:

change(arg1, arg2, arg3);
If giving parameters the same names as their arguments is a problem, compiling params.cpp will produce errors. If the names matter, then we might see a change in the values in the main program.

Observation: Compile and execute your program.

Question #8.3.2: Were you able to compile your program?

Question #8.3.3: If not, what error message did you get? If you could compile, what did the program print when you ran it?


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

Undo your modifications and then continue.

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