Because you are calling ab() inside itself, and ab() produces that sort of output?
--
Mats
Because you are calling ab() inside itself, and ab() produces that sort of output?
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Okay, think about this:
Produces the expected:Code:#include "stdio.h" #define max(a,b) (a)>(b)? a : b int g=0; int testfunc (int X, int Y) { return max(X,Y); } int ab(int n, int a) { if (n==0) return 5; printf("a=.....%d\n",a); printf("g=.....%d\n",g); printf("-------------\n"); g=-50; a-=1; g=testfunc(g,ab(n-1,a)); printf("a(%d)==========%d\n",n,a); return g; } void main(void) { ab(2,10); }
a=.....10
g=.....0
-------------
a=.....9
g=.....-50
-------------
a(1)==========8
a(2)==========9
ps. look for stuff about the Fibonacci set, that is the essential form of recursion I think
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge