curious result

Hi.Why is it that the following code doesn't print 5 consecutive zero in f1 calls?
1
2
3
4
5
6
7
8
9
10
11
12
13
f1(const int x)
{
         printf("%d", x);
         if(x==0)return 0;
         else {printf("\n%d", 2*f1(x-1) );//return 2*f1(x-1)+x*x;
          }
}
main()
{
      printf("\n*********main***********\n%d", f1(5));
      
      while(1);
}

What does it print?

It can't be compiled in C++ or modern C (missing return type), and it can't be compiled in the ancient C89, where this f1 returns int, because "//" was not a valid comment.

In any case, falling off the end of a value-returning function without a return statement has always been undefined behavior.
not in c, c + + but, first declaring data type returned by the function "f1".
missing the "# include <xxxxx>" "using namespace std;" the loop "while" is misspelled ...
should do the code again
the orginal problem was:
1
2
3
4
5
6
7
8
9
10
11
12
f1(const int x)
{
         if(x==0)return 0;
         else {return 2*f1(x-1)+x*x;
          }
}
main()
{
      printf("%d", f1(5));
      
      while(1);
}


I tried to see whether 2*f1(x-1) is computed first, or f1(x-1 is.seems I were wrong.
(run my code as a C code)
How could 2* the return value of f1(x-1) be calculated before the return value was calculated?



not calculated, but parsed
What does parsed mean to you?
Topic archived. No new replies allowed.