Experiment 5: Reference Parameters


The Question: If a function alters the value of one of its reference parameters, what affect will that have on the corresponding argument?

Hypothesis: Review the reference parameter definition, and then construct a hypothesis.



The Experiment: We can test your hypothesis by making two of the parameters in Change() a reference parameter. Such a change must be made in both the prototype:

   void Change(int & param1, int & param2, int param3);
and in the definition:
   void Change(int & param1, int & param2, int param3)
   {
       param1 = 1;
       param2 = 2;
       param3 = 3;
   }

Observation: Translate and execute your program. What is displayed ?



Conclusions: Review the definitions of value and reference parameters, and explain what happened. What determines the parameter with which an argument is associated?








Back to the Lab Exercise

Forward to the Next Experiment


Copyright 1998 by Joel C. Adams. All rights reserved.