By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,961 Members | 1,332 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,961 IT Pros & Developers. It's quick & easy.

Is class is occupying any Memory??

P: 1
hi,
I want to know is class is occupying any Memory??

suppose if i declare 10 different classes and don't create any instance of that classes, is that classes occupying any Memory??

class var
{
int a;
int b;
float c;
float d;
};

is the memory is allocated for this class???

regards,
fiem
Aug 14 '07 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
No. Memory is not allocated when you declare a class. The class serves as information for the compiler os that when you create an object the compiler knows how big to make it. Then when you call methods on the object, the compiler can check to see of the methods are actualy part of the class. Only when you define an object is memory allocated:
Expand|Select|Wrap|Line Numbers
  1. //class declaration - no memory allocated
  2. class var
  3. {
  4. int a;
  5. int b;
  6. float c;
  7. float d;
  8. };
  9.  
  10. int main()
  11. {
  12.     var obj;          //object defined. Memory is allocated.
  13. }
  14.  
Aug 14 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.