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 😀

Nothing in memory

Full screenshot available here

Now when you define that static variable befor the Main Clause you get a memory location

Static 2
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 .


~ by Azeem on May 18, 2008.

4 Responses to “Superseding some Pre-Concepts Of Static Data members”

  1. 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.

  2. Yes ! and this is the point static data members need to be re initialized in the file scope

  3. hehe…really? Thank God I am out of coding…

  4. Somehow i missed the point. Probably lost in translation 🙂 Anyway … nice blog to visit.

    cheers, Miniaturist.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: