Due: Friday, November 10, 2017, 11:00 am (Session A) 1:00 pm (Session B) (start of the class)

The following C code tries to find the maximum between a and b and pass the maximum back to the calling function. Read the code and answer the questions.

int max (int max, int a, int b) {
	if (a >= b) max = a;
	else        max = b;

	return 0;
}

int main () {
	int m = 0, a = 3, b = 5;
	printf("Before calling max: a = %d, b = %d, max = %d\n", a, b, m);
	max(m, a, b);
	printf("After calling max: a = %d, b = %d, max = %d\n", a, b, m);

	return 0;
}
  1. What is the output of the code?
  2. Can this code pass the maximum back to the main function successfully?
  3. How to modify the code to make the maximum be returned to the calling fucntion without changing the return statement in the max function?

© 2017 Ying Li. Page last modified: .