GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 115 of 203    Print  
Why the size of empty Class is one byte?

  
Total Answers and Comments: 4 Last Update: October 18, 2007     Asked by: varun goswami 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
February 20, 2007 03:35:15   #1  
swetha        

RE: why the size of empty class is one byte.

creating the object means creating the memory therefore even though there are no
members in the class also it will create a phsical memory location of 1 byte and gets the address(object is reality)


 
Is this answer useful? Yes | No
March 22, 2007 10:01:56   #2  
Gunvant Member Since: March 2007   Contribution: 4    

RE: why the size of empty class is one byte.
Yeah true. Just to mark its existence size is 1 byte.
 
Is this answer useful? Yes | No
June 03, 2007 17:18:10   #3  
pulak        

RE: why the size of empty class is one byte.
The handler consumes one byte if class is empty.
 
Is this answer useful? Yes | No
October 18, 2007 18:43:04   #4  
ransome        

RE: Why the size of empty Class is one byte?
Yes the compiler will generate 1 byte of memory to mark the existence of the class. This doesn't answer WHY though. The reason is the language standard states that all classes must have a memory size of at least 1 byte so that the class doesn't occupy the same memory space with another class. This is to prevent name mangling. i.e. if I declare a class A {}; the compiler will still generate an entry in its table to something called "A". If behind that I declare another class say class B if A takes 0 bytes of memory and B's data gets written in the place where A was declared. In this case an instantiation of A would take on the properties of B.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape