/* */ Click to Join Live Class with Shankar sir Call 9798158723

What is Static scope ?

The varibale that are define using the keyword static are called static variable.The space for the static variable is allocated only one time and this is used for the entirety of the program.The scope of a static variable is local to the block in which the variable is defined. However, the value of the static variable persists between two function calls.

some feature of static variable.

  1. Static variable are initialized to 0 by degault.
  2. They are define inside the function, their scope is limited to the function only and other function cannot access the variables.
  3. But, if they are declared inside non-member function they have characteristices of both global variable and local variables.
  4. Static global variables declared at the top level of the C source file have the scope that they can not be visible external to the source file. The scope is limited to that file.

Q.) Example of Static Variables in C++ .
#include < iostream>
#include < string>
using namespace std;

void demo()
	// static variable
	static int count = 0;
	cout << count << " ";
	// value is updated and
	// will be carried to next
	// function calls

int main()
	for (int i=0; i< 5; i++)	
	return 0;

0 1 2 3 4