Why this code gives a segmentation fault error?
Hi there,
I don't know why this code gives a segmentation fault error,
Code:
# include <stdio.h>
# include <math.h>
long move(int GoRight, int GoDown) {
long i = 0;
if (GoRight > 0) {
i = i + 1 + move(GoRight - 1, GoDown);
}
if (GoDown > 0) {
i = i + 1 + move(GoRight - 1, GoDown);
}
return i;
}
int main(void) {
printf("%ld\n", move(2, 2));
return 0;
}
while the one below doesn't:
Code:
# include <stdio.h>
# include <math.h>
long move(int GoRight) {
long i = 0;
if (GoRight > 0) {
i = i + 1 + move(GoRight - 1, GoDown);
}
return i;
}
int main(void) {
printf("%ld\n", move(2));
return 0;
}
Some hints, please?