1 |
h09 |
CS16 Su17 |
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" |
h09: Chapter 5: Call by value and call by reference
ready? | assigned | due | points |
---|---|---|---|
true | Tue 07/25 02:00PM | Tue 08/01 02:00PM |
You may collaborate on this homework with AT MOST one person, an optional "homework buddy".
MAY ONLY BE TURNED IN IN THE LECTURE/LAB LISTED ABOVE AS THE DUE DATE,
OR IF APPLICABLE, SUBMITTED ON GRADESCOPE. There is NO MAKEUP for missed assignments;
in place of that, we drop the three lowest scores (if you have zeros, those are the three lowest scores.)
Please:
- No Staples.
- No Paperclips.
- No folded down corners.
Read Chapter 5.1 thru 5.4 (If you do not have a copy of the textbook yet, there is one on reserve at the library under “COMP000-STAFF - Permanent Reserve”). Read the lecture slides for topics on binary arithmetic.
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.(3 pts) What happens if you forget the return statement in a void-function?
2.(3 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.(4 pts) Write a void-function definition for a function called “zero_both” with 2 parameters, both which are variables of type int, and sets the value of both variables to 0. Describe if you picked this function to be a call-by-reference or a call-by-value AND WHY?
5.(2 pts) What is the value of the concepts of pre-condition and post-condition to programmers?
6.(4 pts) What are two important testing strategies covered in the book?
7.(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;
}
8.(2 pts) What is the meaning of the ampersand character (&) in the code above?