Superseding some Pre-Concepts Of Static Data members
Well 3 years back i studied OOP and at that time we had a one simple rule in our mind
What ever teacher teaches i always right ! If you think teacher is wrong then you’re a moron!
For what i remember we all have been told that static datamembers exists without there object being made
since that time i use to belive that static data members are created at compilation time and the memory gets
allocated to them without there object being made! I never cared about it i just belived what was told to me until today ! i thought of trying static data members out and check weather they really exists without there object being made
Lets assume we haveĀ a class
class A {
public :
static int i;
};
int _tmain(int argc, _TCHAR* argv[])
{
A abc;
return 0;
}
What i pressumed is that static data member would have been allocated memory at the compile time but found out that it really doesnt
Full screenshot available here
Now when you define that static variable befor the Main Clause you get a memory location

Full screenshot available here
One thing more the memory location of the object and the static variable are totally seprated !
So Moral of the story dont believe things until you try them out and Static data members have no existence like a class have no existence in memory until they are defined after the class .





Each static data member must be initialized once (and only once) at file scope. This is what is being done in the second snapshot. I guess this is the point where memory gets allocated and initialized at the time of allocation.
Yes ! and this is the point static data members need to be re initialized in the file scope
hehe…really? Thank God I am out of coding…
Somehow i missed the point. Probably lost in translation
Anyway … nice blog to visit.
cheers, Miniaturist.