1
h05
CS16 S19
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 Fri 04/26 09:00AM Fri 05/03 11:59PM

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 GAUCHOSPACE. There is NO MAKEUP for missed assignments.


Please:

  • No Staples.
  • No Paperclips.
  • No folded down corners.

Read Chapter 5.1 thru 5.4. You don’t need to turn this homework in. To earn credit for this homework, complete the corresponding quiz on gauchospace AFTER you have completed the pen and pencil version of the homework. The quiz will be available one day before the due date indicated on the homework.

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?