Why the value of static variable a
is not incrementing even after return statement?
#include<stdio.h>
int p(int x);
int main()
{
int r=p(4);
printf("%d",r);
return 0;
}
int p(int x)
{
static a=1;
printf(" x = %d,a= %d\n",x,a);
if(x<=1)
{
return 1;
}
else
{
printf(" x = %d,a= %d\n",x,a);
return p(x-1)+x+a++;
printf(" x = %d,a= %d\n",x,a);
}
}
Here, when I print static variable a
then all time its value is 1. But according to the theory I read, it should be incremented after each recursive call.