void func(int num){
if(num< 3){
printf("%d ", num);
func(num+ 1);
printf("%d ", num);
}
}
Suppose I call this function with func(0). Why is the result 0 1 2 2 1 0 ? I don't know why it's decreasing.
Here's a stack trace
f(0)
print 0
f(1)
print 1
f(2)
print 2
f(3) // 3 < 3 == false
print 2
print 1
print 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With