38.0k views
3 votes
what is the difference between recursion and iteration in C, and their advantages and disadvantages? ...?

1 Answer

5 votes

I think both recursive and iteration are different programming approaches which have their own benefits and drawbacks .

Recursive approach: In recursive approach the function calls itself until the condition is met. And it is slower than iteration,which means it uses more memory than iteration. recursion is like a selection structure, and which makes code smaller and clean. And a function partially defined by itself. Here tracing the code will be more difficult in the case large programs.Iterative approach: Iterative approach is a repetition process until the condition fails,here loops are used such as for ,while etc. Here code may be longer but it is faster than recursive. And it consumes less memory compared to recursive approach.If the loop condition is always true in such cases it will be an infinite loop.
User Meiryo
by
6.8k points