The keyword static is one which has several meanings in C++ that I find very confusing and I can never bend my mind around how its actually supposed to work.
It's actually quite simple. If you declare a variable as static in the scope of a function, its value is preserved between successive calls to that function. So:
int myFun()
{
static int i=5;
i++;
return i;
}
int main()
{
printf("%d", myFun());
printf("%d", myFun());
printf("%d", myFun());
}
will show 678 instead of 666, because it remembers the incremented value.
As for the static members, they preserve their value across instances of the class. So the following code:
struct A
{
static int a;
};
int main()
{
A first;
A second;
first.a = 3;
second.a = 4;
printf("%d", first.a);
}
will print 4, because first.a and second.a are essentially the same variable. As for the initialization, see this question.