A static data member of a class is just like a global variable for its class. That is, this data member is globally available for all the objects of that class type. The static data members are usually maintained to store values common to the entire class. For instance, a class may have a static data member keeping track of its number of existing objects.
A static data member is different from ordinary data members of a class in various respects:
There is only one copy of a static data member maintained for the entire class which is shared by all the objects of that class.
It is visible only within the class; however, its lifetime (the time for which it remains in the memory) is the entire program.
Two things are needed for making a data member static:
Declaration within the class definition
Definition outside the class definition.
The declaration of a static data member within the class definition is similar to any other variable declaration except that it starts with the keyword static as shown below:
class X { static int count ; // declaration within the class. ------- }