Question 46
What will be the output of the following C program?
C
#include <stdio.h>
int val(int n) {
static int c = 0;
if (n <= 0) return c;
c += n;
return val(n - 1);
}
int main(void) {
printf("%d", val(4));
return 0;
}Detailed Solution
c accumulates 4 + 3 + 2 + 1 = 10. When n=0, returns c = 10.
✓ Saved