Step 4: Passing Arguments "By-Reference"

Now, we will practice "pass-by-reference" parameter-passing. Recall from lecture that when we use "call-by-reference", we are no longer working with a copy of the caller's arguments, but with the actual original. Therefore, modifying these parameter variables will affect the values of variables in the caller's context.

What To Do:

This step is quite easy. Just cut-and-paste the entire definition of ModifyDate() from Step 3 and rename the new copy of the function as tModifyDateForReal(). Then, modify the function's parameter specification to indicate that the parameter is "pass-by-reference"--try to recall how to do this from lecture. If you can't remember, the TA will tell you what to do.

Because the body of this function is exactly the same as ModifyDate(), it will behave much the same.

After writing this function, you should add the necessary function declaration for ModifyDateForReal() at the top of your file, above main().

For the second part of this step, add a call in main() to ModifyDateForReal(), right after the code you added in the previous step. You should be able to cut-and-paste to duplicate the code you added into main() for Step 3, simply modifying the name of the function called. Don't forget to also duplicate the part that outputs the values of the members of myDate, just as for Step 3.

Once again, save your changes, run "make" to recompile your program, and run it. What do you observe this time?

Finally, show your lab TA your code, Makefile, and a clean execution of your program for full credit. Also explain what you observed, and why it ran that way.