1 |
h05 |
CS16 F19 |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | section |
||
Optional: name you wish to be called if different from name above. | ||||
Optional: name of "homework buddy" (leaving this blank signifies "I worked alone" |
h05: Chapter 5: Call by value and call by reference
ready? | assigned | due | points |
---|---|---|---|
true | Thu 10/31 09:00AM | Thu 11/07 11:59PM |
You may collaborate on this homework with AT MOST one person, an optional "homework buddy".
UPLOAD A PDF OF YOUR ANSWERS TO GRADESCOPE BEFORE THE DUE DATE. ASSOCIATE EACH QUESTION WITH A SPECIFIC PAGE IN YOUR HOMEWORK AT THE TIME OF SUBMISSION. There is NO MAKEUP for missed assignments;
Please:
- No Staples.
- No Paperclips.
- No folded down corners.
Read Chapter 5.1 thru 5.4. Upload your answers as a pdf to the h05 assignment on gradescope.
PLEASE MARK YOUR HOMEWORK CLEARLY, REGARDLESS OF IF YOU WRITE IT OUT IN INK OR PENCIL!
FOR BEST RESULTS, PRINT THIS PAGE AS A PDF, THEN PRINT THE PDF
1.(2 pts) What happens if you forget the return statement in a void-function?
2.(2 pts) Can you define a function in the body of another function? And can you call a function in the body of another function?
3.(2 pts) What is the difference between a call-by-reference function and a call-by-value function? As a programmer, when might you decide to use one over the other?
4.(2 pts) What is the value of the concepts of pre-condition and post-condition to programmers?
5.(4 pts) What are two important testing strategies covered in the book?
6.(6 pts) What is the output of the program below (write it in the space to the right)?
#include <iostream>
using namespace std;
void phooey(int &z) {
z = z / 2;
cout << "z=" << z << endl;
}
int main() {
int b = 3;
phooey(b);
cout << "b=" << b << endl;
return 0;
}
7.(2 pts) What is the meaning of the ampersand character (&) in the code above?