I would like a brief description of the difference between cyclic functions and recursive functions with example.
For example, let us assume we have 3 functions A B and C. I know that if function A calls same function its called recursion. What about if A calls B, then B calls C, and then C calls A?
Can anyone clarify this?
It is called indirect recursion.
void foo(void)
{
bar();
}
void bar(void)
{
foo();
}
In the C Standard (emphasis mine):
(C99, 6.5.2.2p11) "Recursive function calls shall be permitted, both directly and indirectly through any chain of other functions."
Without an exit condition (like in my example), you likely end up in a stack overflow (stack frames are infinitely added at each call until stack is full).
Recursive function is a function that calls itself.
It may call itself directly (A calls A), or indirectly (A calls B, B calls C, C calls A). It's still a recursion.
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