Recursion:
- Function calling itself is called recursion.
- Calling the function from the definition of same function.
Note: Every function in program executes from Stack memory. While executing the program, if the stack is full then program terminates abnormally.
#include<stdio.h>
void recur();
int main()
{
recur();
return 0;
}
void recur()
{
printf("Start\n");
recur();
printf("End\n");
}
We need to take care of function execution completion in recursive call.
Code:
#include<stdio.h>
void abc(int);
int main()
{
abc(3);
return 0;
}
void abc(int x)
{
printf("x : %d\n",x);
if(x>0)
abc(x-1);
}