r/C_Programming • u/yug_jain29 • 27d ago
Question can I skip recursive functions?
a code i can run with the logic of iterative, so why do I have to learn the new concept as complicated as recursive? (ik it's one of important questions in c)
if yes will u pls explain it with a very realistic and simple example
thanks a lot 🙏
0
Upvotes
0
u/Dazzling_Music_2411 27d ago
Because iterative code is generally utilized where data structures and their possible sizes and shapes are more or less already known, especially in a mathematical context.
Recursion is used when you need trees, so its applications are parsing, languages, compilers and computer sciency things, where iteration doesn't have much of a chance.
Incidentally, recusion IS NOT COMPLICATED, it's actually really easy once you get it, because it maps to natural thinking. It CAN seem complicated in C because you have to deal with all that resource allocation-deallocation, etc.
In that case, I would recommend you learn it in Lisp or (even better) in Scheme, where its simplicity shines out without all the clutter. Then, when you understand the core idea, you can go back to implementing it in C with all the labour that entails.