Passing Arrays as Arguments

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. Arrays, however, are effectively passed "by reference", meaning the called function has access to the actual array the caller is passing in, and any changes made by the called function will be seen by the caller upon return. This was done by the language designers for efficiency reasons, and can be considered potentially dangerous; however, it is very useful to us here.

In this step, you will write a function called getAnswerFromUser, which takes 3 arguments, in this precise order:


The function should output the prompt string, then read the user's input into the array input (go back and look at Lab 2 to refresh yourself on how to read a whole line of text in).

The function returns no value; declare the return type for this function accordingly.

You should now go back up to main() and edit the call to this function to use the specified parameters. The first argument you pass in should be a simple string literal (e.g.: "String to test: "). The second argument should be the buffer that's already declared in main() in the sample code, and you should be able to figure out what you need to pass for the third parameter.

(Note that you will get a warning about using a deprecated feature– ignore this.)