CS471 Programming Language Structure I
Fall 1998

Homework 2

Consider the following program written in C syntax:

int main() {
  int value = 2, list[5] = {1, 3, 5, 7, 9};

  swap(value, list[0]);
  swap(list[0], list[1]);
  swap(value, list[value]);
}
void swap(int a, int b) {
  int temp;
  
  temp = a;
  a = b;
  b = temp;
}

For each of the following parameter passing methods, what are the values of the variable value and all the elements of list after each of the threee calls to swap? (You should list six values for each of the three calls for each method, making 72 in all). Use the definitions of the parameter passing methods as given in chapter 8 of the text book.

  1. pass by value
  2. pass by reference
  3. pass by name
  4. pass by value-result

Assignment due: Monday, October 30th., in class.