1,545 views
5 votes
5 votes
//Consider the following C program
#include <stdio.h>
int f(int *a,int *b,int c) {
  if(c == 0) return 1;
  else {
    *b = *b-1;
    *a = *a+1;
    c = c - 1;
  return *a + f(a,b,c) + *b;
  }
}
int main() {
  int a = 2,b = 2,c = 2;
  printf("%d\n",f(&a,&b,c));
  return 0;
}

Doubts :

  • Is there any undefined behaviour according to C language?
  • if NO, then what will be the output ?
  • Please explain with proper explanation.

Please log in or register to answer this question.

Related questions

1 votes
1 votes
3 answers
1
jverma asked May 23, 2022
1,068 views
#include <stdio.h>int f(int n){ static int r = 0; if (n <= 0) return 1; r=n; return f(n-1) + r;}int main() { printf("output is %d", f(5)); return 0;}Ou...
0 votes
0 votes
0 answers
2
Ajitesh Mandal asked Apr 3, 2017
388 views
What is the output of the program?? I think the output should be 2 2 1 . But on running the program gives the output 2 3 3 . Pls explain why that output 2 3 3 in details ...
0 votes
0 votes
1 answer
3
hacker16 asked Nov 17, 2017
1,132 views
What is the output generated by this code?main(){ int i=0; printf("%d %d %d %d %d %d %d", i++, ++i, i, i++, i, ++i, i++); }4 4 3 2 2 2 04 5 5 2 5 5 00 2 2 2 2 4 4Compiler...