What is recursion in C?
a) A function calling itself
b) A loop inside a function
c) A variable inside a function
d) None of the above
Answer:
a) A function calling itself
Explanation:
Recursion in C occurs when a function calls itself in order to solve a smaller instance of the same problem. This process continues until a base case is met, which stops the recursion. Recursion is a powerful tool for solving problems that can be broken down into smaller, similar sub-problems, such as in algorithms for searching, sorting, and traversing data structures like trees and graphs.
However, recursion should be used carefully as it can lead to stack overflow if the base case is not properly defined or if the recursion depth becomes too large. Understanding recursion is crucial for mastering advanced programming techniques in C.