Question 21
What is the output of the following C program?
#include <stdio.h>
int f(int *p, int n) {
if (n <= 1) return 0;
return *p + f(p + 1, n - 1);
}
int main(void) {
int a[] = {1, 2, 3, 4, 5};
printf("%d", f(a, 5));
return 0;
}Detailed Solution
f sums the first n-1 elements: a[0]+a[1]+a[2]+a[3] = 1+2+3+4 = 10.