1 |
h05 |
CS16 M18 |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | |||
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: Call by value and call by reference
ready? | assigned | due | points |
---|---|---|---|
true | Tue 07/24 08:00AM | Tue 07/31 11:00AM |
You may collaborate on this homework with AT MOST one person, an optional "homework buddy".
MAY ONLY BE TURNED IN IN THE LECTURE 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 four lowest scores (if you have zeros, those are the four lowest scores).
Reading: Sections 5.1 - 5.4
- (10 pts) Fill in the information in the header. The following are required to get the 10 "participation" points.
- Filling in your name and umail address.
- Also: For paper submission PLEASE submit on ONE SHEET OF PAPER, double-sided if at all possible. If you must submit on two printed sheets write name on BOTH sheets and no staples, paperclips, or folded corners.
- Filling in your name and umail address.
- (5 pts) What happens if you forget the return statement in a void-function?
- (5 pts) Can you define a function in the body of another function? And can you call a function in the body of another function?
- (5 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?
- (5 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 pts) What is the value of the concepts of pre-condition and post-condition to programmers?
- (4 pts) What are two important testing strategies covered in the book?
- (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; }
- (5 pts) What is the meaning of the ampersand character (&) in the code above?