Question: In this exercise, you will experiment with passing variables by value and by reference. a. Follow the instructions for starting C++ and viewing the TryThis9.cpp
In this exercise, you will experiment with passing variables by value and by reference.
a. Follow the instructions for starting C++ and viewing the TryThis9.cpp file, which is contained in either the Cpp8\Chap10\TryThis9 Project folder or the Cpp8\Chap10 folder. (Depending on your C++ development tool, you may need to open this exercise’s project/solution file first.)
b. Notice that the main function passes the age variable by value to the getAge function. Run the program. When prompted to enter your age, type your age and press Enter. The message that appears should contain your age; however, it contains the number 0 instead. This is because the age variable is passed by value to the getAge function.
c. Modify the program so that it passes the age variable by reference to the getAge function. Save and then run the program. When prompted to enter your age, type your age and press Enter. This time, the message contains your age.
Step by Step Solution
3.41 Rating (164 Votes )
There are 3 Steps involved in it
To modify the program change the function prototype to void getAge int years and change the funct... View full answer
Get step-by-step solutions from verified subject matter experts
