4. Classification of Recursion
● Internal Recursion Process
● External Recursion Process
● Whenever a recursion function is calling itself
then it is called internal recursion process.
● When one recursion function is calling another
recursion function then it is called external
recursion process.
5. extern int g=5;
void abc()
{
auto int a;
static int s=5;
a=s--;
++g;
printf(“n %d %d %d”, a,s,g);
if(a>=3)
abc();
printf(“%d %d %d”, a,s,g);
}
void main()
{
void xyz(void);
xyz();
}
void xyz()
{
int a;
static int s;
a=s++;
--g;
printf(“n %d %d %d”, a,s,g);
if(a<=1)
{
abc();
xyz();
}
printf(“n %d %d %d”, a,s,g);
}
7. recursion by using main()
● By using auto variable it became stack overflow
● Because for every call auto variable will be
constructed.
void main()
{
int a= 5;
++a;
printf(“%d”, a);
if (a<=6)
main();
printf(“%d”,a);
}
O/p-
6666666666.........Stack overflow
9. Power of a number through recursion:
int power(int b, int e)
{
if (e<0)
return 0;
else if(e==0)
return 1;
else
return(b*power(b-e-1));
}
void main()
{
int a,b,p;
printf(“Enter value of a:”);
scanf(“%d”, &a);
printf(“Enter value of b:”);
scnaf(“%d”, &b);
p=power(a,b);
printf(“n %d^%d value is :
%d”, a,b,p);
}
10. Factorial through recursion.
void main()
{
int n,f;
int fact(int);
printf(“Enter a value:”);
scanf(“%d”, &n);
f=fact(n);
printf(“n %d fact value is: %d”,n,f);
}
int fact(int n)
{
if(n<0)
return 0;
else if(n<=1)
return 1;
else
return (n*fact(n-1));
}
11. Dangling Pointer
● A pointer variable which is pointing to a
dead or inactive location, is called
dangling pointer.
12. Function pointer
● A pointer variable which holds the address of the
function, is called function pointer.
● Function pointer calls are faster then normal
function calls.
● By using function pointer it is possible to pass a
function as a argument to another function.