Any function which calls itself is called *recursive*. Recursive code is usually shorter and easier to understand, but compromises on speed and memory efficiency.

A recursive function solves a problem by calling itself to perform a smaller task.

For example, to calculate the factorial of a number *n*, we know that if we can calculate factorial of (*n*-1), the factorial of *n* can be determined as *n*!=*n*×(*n*−1)!. While doing this, at some point we will reach 0!, which we know for a fact is 1. Therefore: