What happens when you declare the above static variable inside the function say test_function1(). Let us see that. Consider the changes below:
void test_function1()
{
static int function1_call_count;
All_call_count++;
function1_call_count++;
printf("Some function call made %d times\n", All_call_count);
printf("function1 call made %d times\n", function1_call_count);
//The static function1_call_count is only visible here. But end lives forever (till the program lives)
}
A static variable function1_call_count is declared in the function. Now, the variable is visible only inside the function. Other function cannot see it. At the same the even through the visibility is inside the function, the scope is program lifetime. That means, the value persist even after the function returns to the caller. This can be easily examined by calling the function once again as shown below:
int _tmain(int argc, _TCHAR* argv[])
{
test_function1();
test_function2();
test_function3();
test_function1();
getch();
return 0;
}
![Pic2.JPG]()