When a static variable is declared in a file, it has the scope of program runtime. It means, the variable comes alive when the program starts and it dies when the program ends. So what about the visibility? It is visible throughout the entire file.
The code given below shows that the static variable x has visibility all over the file and it goes out of scope when the program ends.
// CPPTST.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <conio.h>
static int All_call_count = 0;
//Function prototypes
void test_function1();
void test_function2();
void test_function3();
void test_function1()
{
All_call_count++;
printf("Some function call made %d times\n", All_call_count);
}
void test_function2()
{
All_call_count++;
printf("Some function call made %d times\n", All_call_count);
}
void test_function3()
{
All_call_count++;
printf("Some function call made %d times\n", All_call_count);
}
int _tmain(int argc, _TCHAR* argv[])
{
test_function1();
test_function2();
test_function3();
getch();
return 0;
}
Output is shown below:

Comments
Join the conversation! Your thoughts help the community grow.