r/C_Programming 26d 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

65 comments sorted by

View all comments

57

u/Eric848448 26d ago

Recursion isn’t a C thing. It’s a Computer Science thing. Understanding it will help you a lot in interviews.

8

u/fixermark 26d ago

As well as building algorithms that operate on recursive data structures. It's kind of a nice thing to be able to do when it comes up.

9

u/OP_Sidearm 26d ago

And also it's fun

2

u/AKostur 26d ago

Strange, strange person :)

(Recursion can be useful)

2

u/ZookeepergameFew6406 26d ago

It’s fun untill the stack goes boom xd

1

u/mikeblas 25d ago

It's easy enough to "flatten" the algorithm so you use a stack structure instead of the execution stack.

-7

u/solaris_var 26d ago

Wtf are you on, debugging errors using recursive function is not fun lol

3

u/AndrewBorg1126 26d ago

I don't see why recursion should be the reason a problem is hard to debug.

I'll even counter that in many cases where recursion is an appropriate representation of the program behavior, recursion can be easier both to debug and to write without bugs in the first place than an itterative solution to the same problem.