1.) Nested Function:
C does not support nested function definitions, which means you cannot define a function inside another function.
- However, nested function calls (i.e., calling a function inside another function) are allowed.
Example:
int multiply(int a, int b) {
return a * b;
}
int square(int x) {
return multiply(x, x); // Nested function call
}- Here, the function square calls the function multiply inside its body — this is a nested function call.
2.) Recursive Function:
A recursive function is a function that calls itself to solve a smaller subproblem.
- It must have a base condition to terminate recursion and prevent infinite loops.
Example:
int factorial(int n) {
if (n == 0)
return 1; // base case
else
return n * factorial(n - 1); // recursive call
}- The factorial function calls itself with a decremented value of n until it reaches 0.
