O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Recursion

Recursion is a programming technique that can be described simply as a function calling itself. This is accomplished by a line calling the function being present inside the function body. This call must be conditionally executed; otherwise the function will continue to call itself forever.

You must define a condition under which the recursion will end and make sure that at some point you reach that point. The implementation will mean either prematurely exiting the function or simply calling the function again, based on the evaluation of a conditional statement.

The technique is tricky to use well but very powerful. It’s effective for traversing arrays or lists of items. One issue with recursion is that it builds a stack of intermediate ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required