Recursion help

closed account (4ET0pfjN)
From this Towers of Hanoi c code, I noticed it doesn't return anything and I learnt that recursion works by storing its local variables, arguments and each function header in a stack frame and return address. So how does recursion work then with Towers of Hanoi example if it doesn't return anything?

1
2
3
4
5
6
7
8
9
10
11
/** solveTowers(n, src, dest, spr) prints instructions for solving the
 *  towers of Hanoi problem that starts with n disks on post src, moving
 *  all of the disks to post dest using post spr as a spare.
 */
void solveTowers(int n, int src, int dest, int spr) {
    if (n > 0) {
solveTowers(n - 1, src, spr, dest);
printf("Move disk %d from post %d to post %d.\n", n, src, dest);
solveTowers(n - 1, spr, dest, src);
    }
}
Topic archived. No new replies allowed.