edited by
5,704 views
12 12 votes
#include <stdio.h>
int f(int *a,int b) {
  b = b-1;
  if(b == 0) return 1;
  else {
    *a = *a+1;
    
  return  *a + f(a,b)  ;
  }
}
int main() {
  int X = 5;
  printf("%d\n",f(&X,X));
}

Predict the output

If the return statement was

return  f(a,b)+ *a ;

What would have been the output here ?  Explain why there is change in output (if any)

1 Answer

Position:
Show:

Related questions

13 13 votes
1 1 answer
1.2k
1.2k views
GO Classes asked Jul 2
1,153 views
Assume:$\texttt{short = 2 bytes}$, $\texttt{int = 4 bytes}$, $\texttt{char = 1 byte}$$\texttt{int}$ needs $4$-byte alignment and the final structure size is rounded to a ...
15 15 votes
2 2 answers
614
614 views
GO Classes asked Jul 2
614 views
Assume:struct Student { double gpa; }; struct Student alice; struct Student *sptr = &alice;Which of the following correctly assigns $\texttt{4.0}$ to $\texttt{alice.gpa}$...
9 9 votes
1 1 answer
459
459 views
GO Classes asked Jul 2
459 views
Consider the following code idea from the source:typedef struct { double x, y; } Point; void reset(Point p) { p.x = p.y = 0; } int main() { Point a = {12.0, 42.0}; Point ...
6 6 votes
1 1 answer
442
442 views
GO Classes asked Jul 2
442 views
What is printed by the following program?#include <stdio.h struct Student { int id, year; char grade; }; int main() { struct Student s; s.id = 10001; s.year = 2010; s.gra...