Lab 9
Due: October 31 (at beginning of lab)
Consider this program that demonstrates pass-by-value and references:
pythagoras.cpp
Answer the following questions on a separate piece of paper to be handed in on the next lab.
All questions refer to pythagoras.cpp
Remember to be as specific as possible.
1. Explain what is going on in line 30.
Write down precisely what happens during the function call and assignment.
2. What is happening in line 31?
Write down precisely what happens during the function call.
Why is a return value not needed for pythagoras2?
3. What is wrong with pythagoras3 (lines 13 to 18)?
How would one fix the problem(s)?
4. Immediately after line 37 is executed, what are the values of c and d,
if a = 3, b = 4, c = 5, and d = 3 just prior to line 37's execution?
5. pythagoras1 is a correctly written function (This is true).
Why would one not use line 38 in a program?
How could this line be fixed in order to achieve something useful?
6. What is wrong with lines 39 and 40?
7. What is the output of lines 44 and 46 if a > 0?
8. Explain the difference between pass-by-value and pass-by-reference.
Use an example if necessary.
Email me if there are any questions.