Step 3: Passing Arguments "By-Value"

By default, C++ passes its parameters "by value", where a function's formal parameters are local variables that hold copies of the values passed in. Therefore, modifying these parameter variables does not affect the values of variables in the caller's context. This rule also applies to structures: by default, copies are passed in and out of functions.

In the first part of this step, you will write a function called MungeRecord(), which takes one argument: a Record structure. The function does not return any value, and should therefore be declared void.

Inside the function, you should swap the m_firstName and m_lastName members of the structure, and set the m_age member to -1. You should be doing these modifications to the parameter variable.

The function should then print out the updated struct members before returning. You can just cut-and-paste the code you already wrote into main() in Step 2 to do output.

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

For the second part of this step, add a call in main() to MungeRecord(), passing in myRec as an argument. After the call to MungeRecord() returns, print out the members of myRec from inside main(). Again, you can just cut-and-paste the code you already wrote in Step 2 to do this.

What do you observe?