Written and tested in Visual Studio Express
Code:
#include<stdio.h>
void numberline(int depth);
void main()
{
numberline(5);
}
void numberline(int depth)
{
if(depth == 0) {
printf("0");
return;
}
printf("%d", depth);
numberline(depth - 1);
printf("%d", depth);
}
Output: 54321012345
I have debugged this little program: until the zero everything is obvious but then...
What exactly is being returned (it is a void function)?
Why that jump after the return to the last line of that numberline-function?
Why is the variable being increased until it has the same number as the argument which you use for the function? Or is it not being increased and does the program read something from the memory?