Suppose ,there are two functions.
Sum0() and sum1(). An static variable is declared in function sum0; (i.e)
int sum0(
{
static int a=0;// This statement executes during first function call.and for rest of four calls this statement don't executes.
a++;
-------------
-------------
return 0;
}
int Sum1()
{
-----------
-----------
a++;// Here static variable a will not be visible in this function.i.e (scope of a static variable is limited to the function in which it is defined );
}
int main( )
{
for(int i=0;i<5;i++)
sum0();/*when this function is called five times local static variable a is defined once i.ememory
is allocated once and value increments five times. After function returns last time,memory is
deallocated . (i.e) static variables span across function calls.
return 0;
}