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.

What To Do:

In the first part of this step, you will write a function called ModifyDate(), which takes one parameter called dateParam, of type Date. The function does not return any value, and should therefore be declared void.

Inside the function, you should set the fields of dateParam to represent your own birthday, and set the m_type field to be 'B', for "birthday". 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 ModifyDate() at the top of your file, above main().

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

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